Module: Tweed::Monads::Maybe::SafeDivision

Defined in:
lib/tweed/monads/maybe.rb

Overview

An example of safe division implemented over the Maybe monad.

Instance Method Summary collapse

Instance Method Details

#/(other) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/tweed/monads/maybe.rb', line 27

def /(other)
  self.bind do |x|
    other.bind do |y|
      y.zero? ? self.class.zero : self.class[x / y]
    end
  end
end