This is another wrong, incomplete implementation of Maybe data type in Ruby.
This gist is a full-blown gem. In order to use it, just add the following line to your Gemfile.
gem 'maybe', gist: 'da2aaafdfd71e6ff0ffd'
To my knowledge, all existing gems are too fat and do not provide the ability to configure what values should be treated as Just
and what values are Nothing
. Some treat []
as Nothing
, some treat only nil
as Nothing
, some rely on truthiness (this is the most reasonable choice in my opinion). In my particular use case, I needed to treat obj
as Nothing
iff obj.present?
is true
. Obviously, hard-coding this Railsism into the gem is not an option, so I pass the Nothingness predicate into Maybe data constructor (pardon my French).