Top Level Namespace

Includes:
Monadic

Defined Under Namespace

Modules: Either, Monadic Classes: Failure, Success, Validation

Constant Summary collapse

None =
Monadic::None
Some =
Monadic::Some

Constants included from Monadic

Monadic::VERSION

Instance Method Summary collapse

Instance Method Details

#Either(value) ⇒ Object



90
91
92
93
# File 'lib/monadic/either.rb', line 90

def Either(value)
  return Failure(value) if value.nil? || (value.respond_to?(:empty?) && value.empty?) || !value
  return Success(value)
end

#Failure(value) ⇒ Object



86
87
88
# File 'lib/monadic/either.rb', line 86

def Failure(value)
  Failure.new(value)
end

#Option(value) ⇒ Object Also known as: Some, Maybe

Helper function which returns Some or None respectively, depending on their value I find this moar simplistic in ruby than the traditional #bind and #unit



7
8
9
10
# File 'lib/monadic/option.rb', line 7

def Option(value)
  return Monadic::None if value.nil? || (value.respond_to?(:empty?) && value.empty?)
  return Monadic::Some.new(value)
end

#Success(value) ⇒ Object



82
83
84
# File 'lib/monadic/either.rb', line 82

def Success(value)
  Success.new(value)
end

#Validation(&block) ⇒ Object



1
2
3
# File 'lib/monadic/validation.rb', line 1

def Validation(&block)
  Validation.new.call(&block)
end