module Mooset::Monad
Public Instance Methods
method_missing(*args, &block)
click to toggle source
# File lib/mooset/monads.rb, line 9 def method_missing(*args, &block) within do |value| begin value.public_send(*args, &block) rescue require 'pry'; binding.pry end end end
within(&block)
click to toggle source
# File lib/mooset/monads.rb, line 3 def within(&block) and_then do |value| self.class.from_value(block.call(value)) end end
Private Instance Methods
ensure_monadic_result(&block)
click to toggle source
# File lib/mooset/monads.rb, line 21 def ensure_monadic_result(&block) acceptable_result_type = self.class ->(*a, &b) do block.call(*a, &b).tap do |result| unless result.is_a?(acceptable_result_type) raise TypeError, "block must return #{acceptable_result_type.name}" end end end end