ruby-possibly
ruby-possibly copied to clipboard
Release 0.3.0
Release 0.3.0
Breaking changes
-
or_elseis renamed toget_or_else. This change unifies the API naming. All the methods that start withget_return the unwrapped value. Migration: Go through your project and replace allor_elsemethods calls toget_or_else
Additions
- The new
or_elsemethod: Returns the currentMaybeif it'sSome, otherwise it returns what is given as a parameter.
Maybe("a").or_else { Maybe("b") }.map(&:upcase) # => "A"
Maybe(nil).or_else { Maybe("b") }.map(&:upcase) # => "B"
-
combine: Takes twoMaybes and returns a newMaybewhich contains and array of the values of the two combinedMaybes.
Maybe(14).combine(Maybe(23)).map { |(a, b)| a + b }.get # => 37
-
inner: Forwards the method call straight to the value. This is especially useful if the value is an array.
Maybe([1, 5, 3, 7, 9, 6]).inner.max.get # => 9
-
lazy:Maybecan be used lazily. You can calllazyto anyMaybeand get back a lazy version. Also, you can initialize a newMaybelazily by giving it a block. In 0.3.0, lazy is opt-in, but the plan is to make it a default in the future versions.