Class: Unsound::Data::Nothing

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

Instance Method Summary collapse

Methods inherited from Maybe

of

Instance Method Details

#>>Data::Nothing Also known as: and_then

A Noop

Returns:



45
46
47
# File 'lib/unsound/data/maybe.rb', line 45

def >>(*)
  self
end

#fmapData::Nothing

A Noop

Returns:



38
39
40
# File 'lib/unsound/data/maybe.rb', line 38

def fmap(*)
  self
end

#maybe(_, f) ⇒ Object

Call the specified function with no arguments

Parameters:

  • _ (#call)

    a function that will never be called

  • f (#call)

    a function that takes no arguments



62
63
64
# File 'lib/unsound/data/maybe.rb', line 62

def maybe(_, f)
  f[]
end

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

Chain another operation which can result in a Maybe

Parameters:

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

    the next operation

Returns:



54
55
56
# File 'lib/unsound/data/maybe.rb', line 54

def or_else(f = nil, &blk)
  (f || blk).call
end