class Rumonade::Either::RightProjection
Attributes
@return Returns the Either
value
Public Class Methods
@return [RightProjection] Returns the empty RightProjection
# File lib/rumonade/either.rb, line 250 def empty self.new(Left(nil)) end
@param either_value
[Object] the Either
value to project
# File lib/rumonade/either.rb, line 256 def initialize(either_value) @either_value = either_value end
@return [RightProjection] Returns a RightProjection
of the Right
of the given value
# File lib/rumonade/either.rb, line 245 def unit(value) self.new(Right(value)) end
Public Instance Methods
@return [Boolean] Returns true
if other is a RightProjection
with an equal Either
value
# File lib/rumonade/either.rb, line 264 def ==(other) other.is_a?(RightProjection) && other.either_value == self.either_value end
@return [Boolean] Returns true
if Left
or returns the result of the application of the given function to the Right
value.
# File lib/rumonade/either.rb, line 286 def all?(lam = nil, &blk) !either_value.right? || bind(lam || blk) end
@return [Boolean] Returns false
if Left
or returns the result of the application of the given function to the Right
value.
# File lib/rumonade/either.rb, line 276 def any?(lam = nil, &blk) either_value.right? && bind(lam || blk) end
Binds the given function across Right
.
# File lib/rumonade/either.rb, line 269 def bind(lam = nil, &blk) if !either_value.right? then either_value else (lam || blk).call(either_value.right_value) end end
Returns the value from this Right
or raises NoSuchElementException
if this is a Left
.
# File lib/rumonade/either.rb, line 291 def get if either_value.right? then either_value.right_value else raise NoSuchElementError end end
Returns the value from this Right
or the given argument if this is a Left
.
# File lib/rumonade/either.rb, line 296 def get_or_else(val_or_lam = nil, &blk) v_or_f = val_or_lam || blk if either_value.right? then either_value.right_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 317 def inspect "RightProjection(#{either_value.inspect})" end
@return [Either] Maps the function argument through Right
.
# File lib/rumonade/either.rb, line 307 def map(lam = nil, &blk) bind { |v| Right((lam || blk).call(v)) } end
@return [Option] Returns None
if this is a Left
or if the given predicate does not hold for the Right
value, otherwise, returns a Some
of Right
.
# File lib/rumonade/either.rb, line 281 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 Right
value if it exists or a None
if this is a Left
.
# File lib/rumonade/either.rb, line 302 def to_opt Option(get_or_else(nil)) end
@return [String] Returns a String
representation of this object.
# File lib/rumonade/either.rb, line 312 def to_s "RightProjection(#{either_value})" end