class Rumonade::Either::LeftProjection
Attributes
@return Returns the Either
value
Public Class Methods
@return [LeftProjection] Returns the empty LeftProjection
# File lib/rumonade/either.rb, line 169 def empty self.new(Right(nil)) end
@param either_value
[Object] the Either
value to project
# File lib/rumonade/either.rb, line 175 def initialize(either_value) @either_value = either_value end
@return [LeftProjection] Returns a LeftProjection
of the Left
of the given value
# File lib/rumonade/either.rb, line 164 def unit(value) self.new(Left(value)) end
Public Instance Methods
@return [Boolean] Returns true
if other is a LeftProjection
with an equal Either
value
# File lib/rumonade/either.rb, line 183 def ==(other) other.is_a?(LeftProjection) && other.either_value == self.either_value end
@return [Boolean] Returns true
if Right
or returns the result of the application of the given function to the Left
value.
# File lib/rumonade/either.rb, line 205 def all?(lam = nil, &blk) !either_value.left? || bind(lam || blk) end
@return [Boolean] Returns false
if Right
or returns the result of the application of the given function to the Left
value.
# File lib/rumonade/either.rb, line 195 def any?(lam = nil, &blk) either_value.left? && bind(lam || blk) end
Binds the given function across Left
.
# File lib/rumonade/either.rb, line 188 def bind(lam = nil, &blk) if !either_value.left? then either_value else (lam || blk).call(either_value.left_value) end end
Returns the value from this Left
or raises NoSuchElementException
if this is a Right
.
# File lib/rumonade/either.rb, line 210 def get if either_value.left? then either_value.left_value else raise NoSuchElementError end end
Returns the value from this Left
or the given argument if this is a Right
.
# File lib/rumonade/either.rb, line 215 def get_or_else(val_or_lam = nil, &blk) v_or_f = val_or_lam || blk if either_value.left? then either_value.left_value else (v_or_f.respond_to?(:call) ? v_or_f.call : v_or_f) end end
@return [String] Returns a String
containing a human-readable representation of this object.
# File lib/rumonade/either.rb, line 236 def inspect "LeftProjection(#{either_value.inspect})" end
@return [Either] Maps the function argument through Left
.
# File lib/rumonade/either.rb, line 226 def map(lam = nil, &blk) bind { |v| Left((lam || blk).call(v)) } end
@return [Option] Returns None
if this is a Right
or if the given predicate does not hold for the left
value, otherwise, returns a Some
of Left
.
# File lib/rumonade/either.rb, line 200 def select(lam = nil, &blk) Some(self).select { |lp| lp.any?(lam || blk) }.map { |lp| lp.either_value } end
@return [Option] Returns a Some
containing the Left
value if it exists or a None
if this is a Right
.
# File lib/rumonade/either.rb, line 221 def to_opt Option(get_or_else(nil)) end
@return [String] Returns a String
representation of this object.
# File lib/rumonade/either.rb, line 231 def to_s "LeftProjection(#{either_value})" end