Class: Unsound::Data::Right

Inherits:
Either
  • Object
show all
Defined in:
lib/unsound/data/either.rb

Instance Method Summary collapse

Methods inherited from Either

of

Instance Method Details

#>>(f = nil, &blk) ⇒ Data::Left, Data::Right Also known as: and_then

Chain another operation which can result in a Either

Parameters:

  • f (#call) (defaults to: nil)

    the next operation

Returns:



80
81
82
# File 'lib/unsound/data/either.rb', line 80

def >>(f = nil, &blk)
  (f || blk)[value]
end

#either(_, f) ⇒ Object

Call a function on the value in the Unsound::Data::Right

Parameters:

  • _ (#call)

    a function that will never be called

  • f (#call)

    a function capable of processing the value



96
97
98
# File 'lib/unsound/data/either.rb', line 96

def either(_, f)
  f[value]
end

#fmap(f = nil, &blk) ⇒ Data::Right

Apply a function to a value contained in a Unsound::Data::Right

Parameters:

  • f (#call) (defaults to: nil)

    the function to apply

Returns:



72
73
74
# File 'lib/unsound/data/either.rb', line 72

def fmap(f = nil, &blk)
  self >> Composition.compose(method(:of), (f || blk))
end

#or_elseData::Right

A Noop

Returns:



88
89
90
# File 'lib/unsound/data/either.rb', line 88

def or_else(*)
  self
end