Class: Tweed::Monads::Maybe

Inherits:
Tweed::Monad show all
Defined in:
lib/tweed/monads/maybe.rb

Overview

The Maybe monad

Defined Under Namespace

Modules: SafeDivision

Instance Method Summary collapse

Methods inherited from Tweed::Monad

[], #bind, #lift_m2, return

Instance Method Details

#==(other) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/tweed/monads/maybe.rb', line 17

def ==(other)
  if other.is_a? Maybe
    [@value, @success] == other.instance_eval { [@value, @success] }
  else
    self.object_id == other.object_id || @value == other
  end
end

#inspectObject



12
13
14
15
# File 'lib/tweed/monads/maybe.rb', line 12

def inspect
  repr = @success ? "[#{@value.inspect}]" : ".zero"
  "#{self.class.inspect}#{repr}"
end