abstract struct Monads::Either(E, T)

Included Modules

Direct Known Subclasses

Defined in:

monads/either.cr

Constructors

Class Method Summary

Instance Method Summary

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 #

[View source]

Class Method Detail

def self.return(value : T) : Right(T) #

[View source]

Instance Method Detail

abstract 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]
abstract 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 inspect(io) #

[View source]
def left? #

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

[View source]
abstract def or(monad : Either) #

[View source]
abstract def or(lambda : E -> U) forall U #

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

[View source]
def right? #

[View source]
def to_s #
Description copied from class Object

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.


[View source]
def value! : E | T #

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

[View source]
abstract def value_or(lambda : E -> U) forall U #

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

[View source]