ruby-possibly icon indicating copy to clipboard operation
ruby-possibly copied to clipboard

Release 0.3.0

Open rap1ds opened this issue 11 years ago • 0 comments

Release 0.3.0

Breaking changes

  • or_else is renamed to get_or_else. This change unifies the API naming. All the methods that start with get_ return the unwrapped value. Migration: Go through your project and replace all or_else methods calls to get_or_else

Additions

  • The new or_else method: Returns the current Maybe if it's Some, 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 two Maybes and returns a new Maybe which contains and array of the values of the two combined Maybes.
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: Maybe can be used lazily. You can call lazy to any Maybe and get back a lazy version. Also, you can initialize a new Maybe lazily 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.

rap1ds avatar Aug 25 '14 07:08 rap1ds