struct Monads::Left(E, T)

Included Modules

Defined in:

monads/either.cr

Constructors

Instance Method Summary

Instance methods inherited from module Monads::Leftable(E, T)

bind(lambda : T -> _) : Leftable(E, T) bind, fmap(lambda : T -> U) : Leftable(E, U) forall U fmap, map_or(default : U, lambda : _ -> _) forall U map_or, or(other : Either)
or(other : E -> _)
or
, value_or(other : E -> _)
value_or(other : U) forall U
value_or

Instance methods inherited from struct Monads::Either(E, T)

<=>(other : Right)
<=>(other : Left)
<=>
, fold(right_fn : T -> U, left_fn : E -> U) forall U
fold(&block : T -> U) forall U
fold
, inspect(io) inspect, left? left?, map_or(default : U, lambda : T -> U) forall U map_or, or(other : Either)
or(other : E -> U) forall U
or(&block : E -> U) forall U
or
, right? right?, to_s to_s, value! : E | T value!, value_or(other : U) forall U
value_or(other : E -> U) forall U
value_or(&block : E -> U) forall U
value_or

Constructor methods inherited from struct Monads::Either(E, T)

new new

Class methods inherited from struct Monads::Either(E, T)

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

Instance methods inherited from struct Monads::Monad(T)

>>(other : Monad(U)) forall U >>, |(other : _ -> Monad(U)) forall U |, bind(lambda : T -> Monad(U)) forall U
bind(&block : T -> Monad(U)) forall U
bind

Constructor methods inherited from struct Monads::Monad(T)

new new, return(v : T) : self return

Instance methods inherited from struct Monads::Functor(T)

fmap(lambda : T -> U)
fmap(&block : T -> U) forall U
fmap
, initialize initialize

Constructor methods inherited from struct Monads::Functor(T)

new new

Constructor Detail

def self.new(data : E) #

[View source]

Instance Method Detail

def <=>(other : Left) #
Description copied from module Comparable(Monads::Either(E, T))

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]

[View source]
def <=>(other : Right) #
Description copied from module Comparable(Monads::Either(E, T))

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]

[View source]
def <=>(other : Either) #
Description copied from module Comparable(Monads::Either(E, T))

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]

[View source]
def <=>(other : LeftException) #
Description copied from module Comparable(Monads::Either(E, T))

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]

[View source]
def bind(lambda : T -> _) : Left(E, T) #

[View source]
def fmap(lambda : T -> U) : Left(E, U) forall U #

[View source]
def fold(right_fn : T -> U, left_fn : E -> U) forall U #
Description copied from struct Monads::Either(E, T)

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) } )


[View source]
def map_or(default : U, lambda : _ -> _) forall U #

[View source]
def map_or(default : U, &block : E -> U) forall U #

[View source]
def or(other : Either) #

[View source]
def or(other : E -> _) #

[View source]
def value! : E #

[View source]
def value_or(other : E -> _) #

[View source]
def value_or(other : U) forall U #

[View source]