Sha256: 6fe0c7387bbb2bca7c0323e2f57db3f9982c113da68a3e063618e14d3198fc76
Contents?: true
Size: 593 Bytes
Versions: 11
Compression:
Stored size: 593 Bytes
Contents
# Adapted from http://stackoverflow.com/questions/2709361/monad-equivalent-in-ruby class LazyIdentity # :nodoc: 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
11 entries across 11 versions & 1 rubygems