Module: Dry::Monads::Maybe::Mixin::Constructors

Included in:
Dry::Monads, Dry::Monads::Maybe::Mixin
Defined in:
lib/dry/monads/maybe.rb

Instance Method Summary collapse

Instance Method Details

#Maybe(value) ⇒ Maybe::Some, Maybe::None

Parameters:

  • value (Object)

    the value to be stored in the monad

Returns:



305
306
307
# File 'lib/dry/monads/maybe.rb', line 305

def Maybe(value)
  Maybe.coerce(value)
end

#NoneMaybe::None

Returns:



325
326
327
# File 'lib/dry/monads/maybe.rb', line 325

def None
  None.new(RightBiased::Left.trace_caller)
end

#Some(value) ⇒ Maybe::Some #Some(&block) ⇒ Maybe::Some

Some constructor

Overloads:

  • #Some(value) ⇒ Maybe::Some

    Parameters:

    • value (Object)

      any value except ‘nil`

    Returns:

  • #Some(&block) ⇒ Maybe::Some

    Parameters:

    • block (Proc)

      a block to be wrapped with Some

    Returns:



319
320
321
322
# File 'lib/dry/monads/maybe.rb', line 319

def Some(value = Undefined, &block)
  v = Undefined.default(value, block || Unit)
  Some.new(v)
end