struct

Monads::Maybe(T)

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

Constructors

Class methods

return(v : T)
Source

Instance methods

<=>(other : Nothing)

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

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
fold(just_fn : T -> U, nothing_fn : -> U) forall U

Fold/match the Maybe: applies just_fn if Just, nothing_fn if Nothing Returns the result of whichever function was applied

Source
fold

Block version of fold - applies block to Just value, raises for Nothing

Source
inspect(io)
Source
just?
Source
map_or(default : U, lambda : T -> U) forall U
Source
map_or(default : U, &block : T -> U) forall U
Source
nothing?
Source
or(other : Maybe)
Source
or(other : -> _)
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_or(other : -> U) forall U
Source
value_or(other : U) forall U
Source
value_or
Source