Data containers
Crystal has many built-in data containers to help you manipulate and organize non-trivial information. The most common by far is the array. Here's a quick overview of the most commonly used data containers in Crystal:
Array
– A linear and mutable list of elements. All values will share a single type, possibly a union.Tuple
– A linear and immutable list of elements where the exact type of each element is preserved and known at compile time.Set
– A unique and unordered group of elements. Values never repeat, and when enumerated, it shows the values in the order they were inserted (without duplicates).Hash
– A unique collection of key-value pairs. Values can be obtained by their keys and can be overwritten, ensuring unique keys. LikeSet
, it is enumerated in insertion order.NamedTuple
– An immutable collection of key-value pairs where every key is known at compile time, as well as the type of each value...