struct

Monads::Either(E, T)

Inherits Comparable / Monads::Monad / Monads::Functor / Struct / Value / Object

Constructors

Class methods

return(value : T) : Right(Nil, T) forall T
Source

Instance methods

<=>(other : Right)

The comparison operator. Returns 0 if the two objects are equal, a negative number if this object is considered less than other, a positive number if this object is considered greater than other, or nil if the two objects are not comparable.

Subclasses define this method to provide class-specific ordering.

The comparison operator is usually used to sort values:

# Sort in a descending way:
[3, 1, 2].sort { |x, y| y <=> x } # => [3, 2, 1]

# Sort in an ascending way:
[3, 1, 2].sort { |x, y| x <=> y } # => [1, 2, 3]
Source
<=>(other : Left)

The comparison operator. Returns 0 if the two objects are equal, a negative number if this object is considered less than other, a positive number if this object is considered greater than other, or nil if the two objects are not comparable.

Subclasses define this method to provide class-specific ordering.

The comparison operator is usually used to sort values:

# Sort in a descending way:
[3, 1, 2].sort { |x, y| y <=> x } # => [3, 2, 1]

# Sort in an ascending way:
[3, 1, 2].sort { |x, y| x <=> y } # => [1, 2, 3]
Source
flat_map(lambda : T -> Either(E, U)) forall U
Source
flat_map
Source
fold(right_fn : T -> U, left_fn : E -> U) forall U

Fold/match the Either: applies right_fn if Right, left_fn if Left Returns the result of whichever function was applied

Example: result.fold( ->(account : Account) { json_response(account) }, ->(error : AuthError) { error_response(error) } )

Source
fold

Block version of fold

Source
inspect(io)
Source
left?
Source
map(lambda : T -> U) forall U
Source
map_or(default : U, lambda : T -> U) forall U
Source
or(other : Either)
Source
or(other : E -> U) forall U
Source
right?
Source
to_s

Returns a nicely readable and concise string representation of this object, typically intended for users.

This method should usually not be overridden. It delegates to #to_s(IO) which can be overridden for custom implementations.

Also see #inspect.

Source
value!
Source
value_or(other : U) forall U
Source
value_or(other : E -> U) forall U
Source
value_or
Source