Class: Mooset::Many

Inherits:
Object
  • Object
show all
Includes:
Monad
Defined in:
lib/mooset/monads.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Monad

#method_missing, #within

Constructor Details

#initialize(values) ⇒ Many

Returns a new instance of Many.



62
63
64
# File 'lib/mooset/monads.rb', line 62

def initialize(values)
  @values = values
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Mooset::Monad

Instance Attribute Details

#valuesObject (readonly)

Returns the value of attribute values.



60
61
62
# File 'lib/mooset/monads.rb', line 60

def values
  @values
end

Class Method Details

.from_value(value) ⇒ Object



72
73
74
# File 'lib/mooset/monads.rb', line 72

def self.from_value(value)
  Many.new([value])
end

Instance Method Details

#and_then(&block) ⇒ Object



66
67
68
69
70
# File 'lib/mooset/monads.rb', line 66

def and_then(&block)
  block = ensure_monadic_result(&block)

  Many.new(values.map(&block).flat_map(&:values))
end