lib/ribimaybe.rb in ribimaybe-0.0.6 vs lib/ribimaybe.rb in ribimaybe-0.0.8

- old
+ new

@@ -75,54 +75,55 @@ # Fetches a value out of a Just and returns the application # of fn to the internal value. # # ==== Attributes # - # * +_+ - Irrelevant default. - # * +fn+ - Function to be applied inside our Just. + # * +_+ - Default value that's never used. + # * +fn+ - Function to be applied to value inside Just. # # ==== Examples # # Just(1).maybe(false) { |x| x == 1 } # => true # Just(1).maybe(42) { |x| x } # => 1 # Contract Any, Proc => Any def maybe(_, &fn) - fn.(@value) + fn.curry.(@value) end # Applies fn to a value inside Just and re-wraps it in another Just. # # ==== Attributes # # * +fn+ - Function to be applied inside Just. # # ==== Examples # - # Just(1).map { |x| x + 1 } # => Just(2) + # Just(1).map { |x| x + 1 } # => Just(2) + # Just { |x, y| x + y }.map { |f| f.(1) } # => Just(#<Proc:...>) # Contract Proc => Just def map(&fn) - Just.new(fn.(@value)) + Just.new(fn.curry.(@value)) end - # Applies fn inside Just to a value in another Just and re-wraps the - # result in another Just. + # Applies fn inside Just to a value in a Just and re-wraps the result in + # a Just. Note that functions are curried by default. # # ==== Attributes # - # * +value+ - Maybe whose value will be use in function application. + # * +value+ - Maybe value. # # ==== Examples # # Just do |x| # x + x # end.apply(Just(1)) # => Just(2) # Contract Or[Nothing, Just] => Or[Nothing, Just] def apply(value) - value.map { |v| @value.(v) } + value.map { |v| @value.curry.(v) } end # Applies fn to value inside Just (note contract constraint). # # ==== Attributes @@ -135,15 +136,15 @@ # rturn(x + x) # end # => Just(2) # Contract Proc => Just def bind(&fn) - fn.(@value) + fn.curry.(@value) end end - # Converts nil to Nothing or lifts value into a Just. Pass either a block - # or a function. + # Converts nil to Nothing or lifts value into a Just. Accepts a optional + # block or value. # # ==== Attributes # # * +value+ - Value to be wrapped. # * +fn+ - Block or function to be wrapped.