Sha256: 528c1f601fbc97324842823c5550e13d1115d42227705b61abc4420433f2d632
Contents?: true
Size: 583 Bytes
Versions: 1
Compression:
Stored size: 583 Bytes
Contents
# Adapted from http://stackoverflow.com/questions/2709361/monad-equivalent-in-ruby class LazyIdentity def initialize(lam = nil, &blk) @lazy = lam || blk @lazy.is_a?(Proc) || raise(ArgumentError, "not a Proc") @lazy.arity.zero? || raise(ArgumentError, "arity must be 0, was #{@lazy.arity}") end attr_reader :lazy def force @lazy[] end def self.unit(lam = nil, &blk) LazyIdentity.new(lam || blk) end def bind(lam = nil, &blk) f = lam || blk f[@lazy] end def ==(other) other.is_a?(LazyIdentity) && other.force == force end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rumonade-0.1.0 | lib/rumonade/lazy_identity.rb |