lib/ribimaybe.rb in ribimaybe-0.0.12 vs lib/ribimaybe.rb in ribimaybe-0.0.13
- old
+ new
@@ -57,13 +57,17 @@
end
# No operation. Always returns Nothing.
#
Contract Proc => Nothing
- def self.bind(&_)
+ def self.bind(fn = nil, &_)
self
end
+
+ class << self
+ alias_method :>=, :bind
+ end
end
class Just
include Contracts
@@ -163,12 +167,14 @@
# Just(1).bind do |x|
# rturn(x + x)
# end # => Just(2)
#
Contract Proc => Or[Nothing, Just]
- def bind(&fn)
- fn.curry.(@value)
+ def bind(fn = nil, &block)
+ (fn || block).curry.(@value)
end
+
+ alias_method :>=, :bind
end
# Converts nil to Nothing or lifts value into a Just. Accepts a optional
# block or value.
#