Class: TAlgebra::Monad::Parser::Optional

Inherits:
TAlgebra::Monad::Parser show all
Defined in:
lib/t_algebra/monad/parser.rb

Constant Summary

Constants inherited from Either

Either::LEFT, Either::RIGHT

Instance Attribute Summary

Attributes inherited from TAlgebra::Monad::Parser

#name

Instance Method Summary collapse

Methods inherited from TAlgebra::Monad::Parser

#as_parser, chain_bind, #extract_parsed, #extract_parsed!, failure, fetch, #fetch, #fetch!, fetch!, #initialize, #is_a?, #optional, parse, #validate, #with_name

Methods included from SingleValued

included

Methods inherited from Either

#==, #from_either, #from_either!, left, #left?, pure, #right?, #to_obj

Constructor Details

This class inherits a constructor from TAlgebra::Monad::Parser

Instance Method Details

#bind(&block) ⇒ Object



93
94
95
96
97
# File 'lib/t_algebra/monad/parser.rb', line 93

def bind(&block)
  return dup if failure? || value.nil?

  required.bind(&block).optional
end

#fmap(&block) ⇒ Object



99
100
101
102
103
# File 'lib/t_algebra/monad/parser.rb', line 99

def fmap(&block)
  return dup if failure? || value.nil?

  required.fmap(&block).optional
end

#requiredObject



105
106
107
# File 'lib/t_algebra/monad/parser.rb', line 105

def required
  Parser.new(is: is, value: value, name: name).required
end