Class: Unsound::Data::Just

Inherits:
Maybe
  • Object
show all
Defined in:
lib/unsound/data/maybe.rb

Instance Method Summary collapse

Methods inherited from Maybe

of

Instance Method Details

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

Chain another operation which can result in a Maybe

Parameters:

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

    the next operation

Returns:



74
75
76
# File 'lib/unsound/data/maybe.rb', line 74

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

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

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

Parameters:

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

    the function to apply

Returns:



66
67
68
# File 'lib/unsound/data/maybe.rb', line 66

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

#or_elseData::Just

A Noop

Returns:



82
83
84
# File 'lib/unsound/data/maybe.rb', line 82

def or_else(*)
  self
end