struct

Monads::Left(E, T)

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

Constructors

new(data : E)
Source

Instance methods

<=>(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
<=>(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 : Either)

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 : LeftException)

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
bind(lambda : T -> _) : Left(E, T)
Source
fmap(lambda : T -> U) : Left(E, U) forall U
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
map_or(default : U, lambda : _ -> _) forall U
Source
map_or(default : U, &block : E -> U) forall U
Source
or(other : Either)
Source
or(other : E -> _)
Source
value!
Source
value_or(other : E -> _)
Source
value_or(other : U) forall U
Source