Ruby Possibly Versions Save

A maybe monad

v1.0.1

7 years ago

First 1.x release!

This release is the first 1.x release, which marks that the project is now officially production ready. The gem is battle tested in real life. We at Sharetribe have been using the gem in our production application since the first version without any issues. In addition to that, the public API of the gem hasn't seen any radical breaking changes for long time, so it's now great time to release the first 1.x version.

What's new?

  • Added or_raise

    or_raise returns an unwrapped value for Some and throws an exception for None. The exception message helps you to spot where the object became None.

    users = Maybe({users: [{name: {first: "John", last: "Doe"}}]})
    
    users[:users][0][:name][:first].or_raise
    # => "John"
    
    users[:users][1][:name][:first].or_raise
    # =>  None::ValueExpectedException: `or_raise` called to None. A value was expected.
    
    # => Maybe    => Some({:users=>[{:name=>{:first=>"John", :last=>"Doe"}}]})
    # => [:users] => Some([{:name=>{:first=>"John", :last=>"Doe"}}])
    # => [1]      => None
    # => [:name]  => None
    # => [:first] => None
    
  • Added or_nil

    or_nil returns an unwrapped value for Some and nil for None. It's equivalent to .or_else(nil)

    users = Maybe({users: [{name: {first: "John", last: "Doe"}}]})
    
    users[:users][0][:name][:first].or_nil # => "John"
    users[:users][1][:name][:first].or_nil # => nil
    

v0.2.0

9 years ago

Adds threequals === operator. This allows Maybe to be used in case expressions. See README for more information.

This release also moves Some and None classes to top-level. They are not anymore wrapped in Maybe module (Maybe::Some, Maybe::None). Also Maybe is now a top-level class, not a module. This change pollutes the global namespace a bit more, but it is required for the case expressions where it is nicer to compare to Some than to Maybe::Some.

When updating, there shouldn't be any breaking changes if you haven't referenced to Maybe::Some or Maybe::None directly or used None constant.

v0.1.1

9 years ago
  • No code changes
  • Update gemspec

v0.1.0

9 years ago
  • Rename none? -> is_none?. none? is an Enumerable method, so it clashed with Maybe#none?
  • Rename some? -> is_some?.

v0.0.3

9 years ago
  • Add equality methods eql? and ==
  • Add implicit and explicit array conversion methods to_ary and to_a
  • Fixes #1: issues with flat_map