Class: Kind::Maybe::Monad

Inherits:
Object
  • Object
show all
Defined in:
lib/kind/maybe/monad.rb

Defined Under Namespace

Classes: Wrapper

Constant Summary collapse

Value =

:nodoc:

->(arg) { arg.kind_of?(Maybe::Monad) ? arg.value : arg }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Monad

Returns a new instance of Monad.



12
13
14
# File 'lib/kind/maybe/monad.rb', line 12

def initialize(value)
  @value = Value[value]
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/kind/maybe/monad.rb', line 8

def value
  @value
end

Instance Method Details

#check(&fn) ⇒ Object Also known as: accept, reject

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/kind/maybe/monad.rb', line 36

def check(&fn)
  raise NotImplementedError
end

#dig(*keys) ⇒ Object

Raises:

  • (NotImplementedError)


49
50
51
# File 'lib/kind/maybe/monad.rb', line 49

def dig(*keys)
  raise NotImplementedError
end

#map(&fn) ⇒ Object Also known as: map!, then, then!, and_then

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/kind/maybe/monad.rb', line 26

def map(&fn)
  raise NotImplementedError
end

#maybe?(matcher) ⇒ Boolean

Returns:



77
78
79
# File 'lib/kind/maybe/monad.rb', line 77

def maybe?(matcher)
  UNDEFINED == matcher || matcher === value
end

#none?Boolean

Returns:

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/kind/maybe/monad.rb', line 20

def none?
  raise NotImplementedError
end

#on {|monad| ... } ⇒ Object

Yields:

  • (monad)


57
58
59
60
61
62
63
# File 'lib/kind/maybe/monad.rb', line 57

def on
  monad = Wrapper.new(self)

  yield(monad)

  monad.output
end

#on_none(matcher = UNDEFINED) {|value| ... } ⇒ Object

Yields:



71
72
73
74
75
# File 'lib/kind/maybe/monad.rb', line 71

def on_none(matcher = UNDEFINED)
  yield(value) if none? && maybe?(matcher)

  self
end

#on_some(matcher = UNDEFINED) {|value| ... } ⇒ Object

Yields:



65
66
67
68
69
# File 'lib/kind/maybe/monad.rb', line 65

def on_some(matcher = UNDEFINED)
  yield(value) if some? && maybe?(matcher)

  self
end

#presenceObject

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/kind/maybe/monad.rb', line 53

def presence
  raise NotImplementedError
end

#some?Boolean

Returns:



24
# File 'lib/kind/maybe/monad.rb', line 24

def some?; !none?; end

#try(_method_name = UNDEFINED, &block) ⇒ Object Also known as: try!

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/kind/maybe/monad.rb', line 43

def try(_method_name = UNDEFINED, &block)
  raise NotImplementedError
end

#value_or(_method_name = UNDEFINED, &block) ⇒ Object

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/kind/maybe/monad.rb', line 16

def value_or(_method_name = UNDEFINED, &block)
  raise NotImplementedError
end