In Seq§

See primary documentation in context for method elems

method elems(Seq:D:)

Returns the number of values in the sequence. If this number cannot be predicted, the Seq is cached and evaluated till the end.

Because an infinite sequence cannot be evaluated till the end, such a sequence should be declared lazy. Calling .elems on a lazy Seq fails with X::Cannot::Lazy.

In Metamodel::EnumHOW§

See primary documentation in context for method elems

method elems($obj)

Returns the number of values.

enum Numbers <10 20>;
say Numbers.^elems;                         # OUTPUT: 2

In role Blob§

See primary documentation in context for method elems

multi method elems(Blob:D:)

Returns the number of elements of the buffer.

my $blob = Blob.new([123]);
say $blob.elems# OUTPUT: «3␤»

In Array§

See primary documentation in context for method elems

method elems(Array:D: --> Int:D)

Returns the number of elements in the invocant. Throws X::Cannot::Lazy exception if the invocant is lazy. For shaped arrays, returns the outer dimension; see shape if you need information for all dimensions.

say [<foo bar ber>.elems# OUTPUT: «3␤» 
say (my @a[42;3;70]).elems# OUTPUT: «42␤» 
 
try [-∞...∞].elems;
say $!.^name;               # OUTPUT: «X::Cannot::Lazy␤»

In Supply§

See primary documentation in context for method elems

method elems(Supply:D: $seconds? --> Supply:D)

Creates a new supply in which changes to the number of values seen are emitted. It optionally also takes an interval (in seconds) if you only want to be updated every so many seconds.

In role Baggy§

See primary documentation in context for method elems

method elems(Baggy:D: --> Int:D)

Returns the number of elements in the Baggy object without taking the individual elements' weight into account.

my $breakfast = bag <eggs spam spam spam>;
say $breakfast.elems;                             # OUTPUT: «2␤» 
 
my $n = ("b" => 9.4"b" => 2).MixHash;
say $n.elems;                                     # OUTPUT: «1␤»

In Capture§

See primary documentation in context for method elems

method elems(Capture:D: --> Int:D)

Returns the number of positional elements in the Capture.

my Capture $c = \(235apples => (red => 2));
say $c.elems# OUTPUT: «3␤»

In IterationBuffer§

See primary documentation in context for method elems

method elems(IterationBuffer:D: --> Int:D)

Returns the number of elements in the IterationBuffer.

In role Setty§

See primary documentation in context for method elems

method elems(Setty:D: --> Int)

The number of elements of the set.

In Any§

See primary documentation in context for method elems

multi method elems(Any:U: --> 1)
multi method elems(Any:D:)

Interprets the invocant as a list, and returns the number of elements in the list.

say 42.elems;                   # OUTPUT: «1␤» 
say <a b c>.elems;              # OUTPUT: «3␤» 
say Whatever.elems ;            # OUTPUT: «1␤»

It will also return 1 for classes.

In Subscripts§

See primary documentation in context for method elems

multi method elems(::?CLASS:D:)

Expected to return a number indicating how many subscriptable elements there are in the object. May be called by users directly, and is also called by postcircumfix [ ] when indexing elements from the end, as in @foo[*-1].

If not implemented, your type will inherit the default implementation from Any that always returns 1 for defined invocants - which is most likely not what you want. So if the number of elements cannot be known for your positional type, add an implementation that fails or dies, to avoid silently doing the wrong thing.

In role Positional§

See primary documentation in context for method elems

method elems()

Should return the number of available elements in the instantiated object.

In Map§

See primary documentation in context for method elems

method elems(Map:D: --> Int:D)

Returns the number of pairs stored in the Map.

my %map = Map.new('a'1'b'2);
say %map.elems# OUTPUT: «2␤»

In Uni§

See primary documentation in context for method elems

method elems(Uni:D: --> Int:D)

Returns the number of codepoints in the invocant.

In Range§

See primary documentation in context for method elems

method elems(Range:D: --> Numeric:D)

Returns the number of elements in the range, e.g. when being iterated over, or when used as a List. Returns 0 if the start point is larger than the end point, including when the start point was specified as . Fails when the Range is lazy, including when the end point was specified as or either end point was specified as *.

say (1..5).elems;                                 # OUTPUT: «5␤» 
say (1^..^5).elems;                               # OUTPUT: «3␤»

In List§

See primary documentation in context for routine elems

sub    elems($list --> Int:D)
method elems(List:D: --> Int:D)

Returns the number of elements in the list.

say (1,2,3,4).elems# OUTPUT: «4␤»