module Collection(X, Y)
Overview
The Collection
module provides an interface and tools for working with any
collection type. This includes both index and key-based containers.
More formally, it models any type that provides a binary relation from X to Y.
Direct including types
Defined in:
collection/collection.crInstance Method Summary
-
#[](key_or_index : X) : Y
Returns the value for the given key_or_index.
-
#[]?(key_or_index : X) : Y | Nil
Returns the value for the given key_or_index, or
nil
. -
#dig(key : X, *subkeys)
Traverses the depth of a structure and returns the value.
-
#dig?(key : X, *subkeys)
Traverses the depth of a structure and returns the value, or nil.
-
#each_pair(&block : Tuple(X, Y) -> ) : Nil
Must yield this structure's key, value or index, element pairs.
-
#each_pair : Iterator(Tuple(X, Y))
Provides an
Iterator
for each pair inself
. -
#nested? : Bool
True is
self
is a nested structure.
Instance Method Detail
Traverses the depth of a structure and returns the value, or nil.
Must yield this structure's key, value or index, element pairs.
Provides an Iterator
for each pair in self
.
NOTE when the base collection provides it own iterator implementation, this method should be overridden to use this directly, this is a generalised implementation and likely sub-optimal in many cases.