Crig::OneOrMany(T)
Inherits Enumerable < Struct < Value < Object
Constructors
merge(items : Enumerable(self)) : self
Sourcenew(pull : JSON::PullParser) : self
Sourceone(item : T) : self
SourceClass methods
Instance methods
empty?
Returns true if self does not contain any element.
([] of Int32).empty? # => true
([1]).empty? # => false
[nil, false].empty? # => false
#present?returns the inverse.
first
Returns the first element in the collection. Raises Enumerable::EmptyError
if the collection is empty.
([1, 2, 3]).first # => 1
([] of Int32).first # raises Enumerable::EmptyError
first_mut
Sourcefirst_ref
Sourceinto_iter
Sourceiter
Sourceiter_mut
Crystal cannot yield Rust-style mutable references, so this iterator returns the same underlying objects for reference types while preserving visit order.
last
Sourcelast_mut
Sourcelast_ref
Sourcelen
Sourcemap_one_or_many
Transforms each item to a new type, returning a new OneOrMany. Unlike Enumerable#map (which returns an Array), this preserves the OneOrMany guarantee.
push(item : T) : Nil
Sourcerest
Sourceto_a
Returns an Array with all the elements in the collection.
(1..5).to_a # => [1, 2, 3, 4, 5]