class Immutable::Vector::Transient(T)

Defined in:

immutable/vector.cr

Constructors

Instance Method Summary

Instance methods inherited from class Immutable::Vector(T)

&(other : Vector(_)) &, +(other : Vector(U)) forall U +, -(other : Vector(_)) -, <<(elem : T) <<, <=>(other : Vector) <=>, ==(other : Vector) ==, [](i : Int) [], []?(i : Int) []?, |(other : Vector(U)) forall U |, any? any?, at(i : Int)
at(i : Int, &)
at
, each(&)
each
each
, each_index(&) each_index, empty? empty?, equals?(other : Vector, &) equals?, first first, first? first?, hash hash, inspect(io : IO) inspect, last last, last? last?, pop : Tuple(T, Vector(T)) pop, pop? : Tuple(T | Nil, Vector(T)) pop?, push(elem : T) push, set(i : Int, value : T) set, size size, to_json(json : JSON::Builder) to_json, to_s(io : IO) to_s, transient(&) transient, uniq uniq

Constructor methods inherited from class Immutable::Vector(T)

new(elems : Array(T))
new
new

Class methods inherited from class Immutable::Vector(T)

[](*elems : T) [], of(*elems : T) of

Constructor Detail

def self.new(trie : Trie(T), tail : Array(T)) #

[View source]
def self.new(elems : Array(T)) #

[View source]
def self.new #

[View source]

Instance Method Detail

def persist! #

[View source]
def pop : Tuple(T, Transient(T)) #
Description copied from class Immutable::Vector(T)

Return a tuple of two things: the last element of the vector and a copy of the vector with the last element removed. Raises IndexError if the vector is empty.

v = Immutable::Vector[1, 2, 3, 4]
last, v2 = v.pop
last # => 4
v2   # => Vector [1, 2, 3]

[View source]
def pop? : Tuple(T | Nil, Transient(T)) #
Description copied from class Immutable::Vector(T)

Like #pop, but returns a tuple of nil and empty vector if called on an empty vector


[View source]
def push(elem : T) #
Description copied from class Immutable::Vector(T)

Returns a new vector with the given value appended to the end, given that the type of the value is T (which might be a type or a union of types).

v = Immutable::Vector["a", "b"]
v.push("c") # => Vector ["a", "b", "c"]
v.push(1)   # => Errors, because the vector only accepts String

# The original vector remains unchanged:
v           # => Vector ["a", "b"]

[View source]
def set(i : Int, value : T) #
Description copied from class Immutable::Vector(T)

Returns a modified copy of the vector with the element at the given index set to the given value.

Negative indices can be used to start counting from the end of the vector. Raises IndexError if trying to set an element outside the vector's range.

vec = Immutable::Vector[1, 2, 3]
vec.set(0, 5) # Vector [5, 2, 3]
vec           # Vector [1, 2, 3]

vec.set(3, 5) # => IndexError

[View source]