lib/option.rb in option-0.1.0 vs lib/option.rb in option-0.1.1

- old
+ new

@@ -50,21 +50,25 @@ def flat_map(&blk) result = blk.call(get) case result when OptionClass then return result - else raise TypeError, "Must be Option" + else raise TypeError, "Must be an Option" end end def fold(if_empty, &blk) blk.call(get) end def exists?(&blk) !! blk.call(get) end + + def filter(&blk) + exists?(&blk) ? self : None + end end class NoneClass < OptionClass def to_a @@ -107,9 +111,13 @@ if_empty.call end def exists?(&blk) false + end + + def filter(&blk) + self end end None = NoneClass.new Some = SomeClass