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.cr

Instance Method Summary

Instance Method Detail

def [](key_or_index : X) : Y #

Returns the value for the given key_or_index.


[View source]
def []?(key_or_index : X) : Y | Nil #

Returns the value for the given key_or_index, or nil.


[View source]
abstract def dig(key : X, *subkeys) #

Traverses the depth of a structure and returns the value.


[View source]
abstract def dig?(key : X, *subkeys) #

Traverses the depth of a structure and returns the value, or nil.


[View source]
abstract def each_pair(&block : Tuple(X, Y) -> ) : Nil #

Must yield this structure's key, value or index, element pairs.


[View source]
def each_pair : Iterator(Tuple(X, Y)) #

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.


[View source]
def nested? : Bool #

True is self is a nested structure.


[View source]