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:



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

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:



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

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

#maybe(f, _) ⇒ Object

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

Parameters:

  • f (#call)

    a function capable of processing the value

  • _ (#call)

    a function that will never be called



99
100
101
# File 'lib/unsound/data/maybe.rb', line 99

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

#or_elseData::Just

A Noop

Returns:



91
92
93
# File 'lib/unsound/data/maybe.rb', line 91

def or_else(*)
  self
end