struct Monads::List(T)

Included Modules

Defined in:

monads/list.cr

Constructors

Class Method Summary

Instance Method Summary

Macro 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(value : Array(T)) #

[View source]

Class Method Detail

def self.return(value) #

[View source]

Instance Method Detail

def +(rhs : List) : List #

[View source]
def <=>(rhs : List) #
Description copied from module Comparable(Monads::List(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 -> List(U)) forall U #

[View source]
def empty? #
Description copied from module Enumerable(T)

Returns true if self is empty, false otherwise.

([] of Int32).empty? # => true
([1]).empty?         # => false

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

[View source]
def head : Maybe(T) #

[View source]
def inspect(io) #

[View source]
def join(sep = "") #
Description copied from module Enumerable(T)

Returns a String created by concatenating the elements in the collection, separated by separator (defaults to none).

[1, 2, 3, 4, 5].join(", ") # => "1, 2, 3, 4, 5"

[View source]
def last #
Description copied from module Indexable(T)

Returns the last element of self if it's not empty, or raises IndexError.

([1, 2, 3]).last   # => 3
([] of Int32).last # raises IndexError

[View source]
def next #
Description copied from module Iterator(T)

Returns the next element in this iterator, or Iterator::Stop::INSTANCE if there are no more elements.


[View source]
def permutations #
Description copied from module Indexable(T)

Returns an Array with all possible permutations of size of self.

a = [1, 2, 3]
a.permutations    # => [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
a.permutations(1) # => [[1],[2],[3]]
a.permutations(2) # => [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]]
a.permutations(3) # => [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
a.permutations(0) # => [[]]
a.permutations(4) # => []

[View source]
def reverse : List(T) #

[View source]
def size #
Description copied from module Enumerable(T)

Returns the number of elements in the collection.

[1, 2, 3, 4].size # => 4

[View source]
def sort : List(T) #

[View source]
def sort(&block : T, T -> U) : List(T) forall U #

[View source]
def sort_by(&block : T -> _) : List(T) #

[View source]
def subsequences #

[View source]
def tail : List(T) #

[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 unsafe_fetch(index : Int) #
Description copied from module Indexable(T)

Returns the element at the given index, without doing any bounds check.

Indexable makes sure to invoke this method with index in 0...size, so converting negative indices to positive ones is not needed here.

Clients never invoke this method directly. Instead, they access elements with #[](index) and #[]?(index).

This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.


[View source]

Macro Detail

macro [](*args) #

create new List

Monads::List[1,2,3] == Monads::List.new([1,2,3])

[View source]