routine elems
Documentation for routine elems
assembled from the following types:
language documentation Subscripts
From Subscripts
(Subscripts) method elems
multi method elems(::?CLASS:)
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.
role Baggy
From Baggy
(Baggy) method elems
Defined as:
method elems(Baggy: --> Int)
Returns the number of elements in the Baggy
object without taking the individual elements weight into account.
my = bag <eggs spam spam spam>;say .elems; # OUTPUT: «2»my = ("b" => 9.4, "b" => 2).MixHash;say .elems; # OUTPUT: «1»
role Setty
From Setty
(Setty) method elems
method elems(--> Int)
The number of elements of the set.
role Positional
From Positional
(Positional) method elems
method elems()
Should return the number of available elements in the instantiated object.
class Range
From Range
(Range) method elems
method elems(Range: --> Numeric)
Returns the number of elements in the range, e.g. when being iterated over, or when used as a List
. Returns Inf if either end point was specified as Inf
or *
.
say (1..5).elems; # OUTPUT: «5»say (1^..^5).elems; # OUTPUT: «3»
class Array
From Array
(Array) method elems
Defined as:
method elems(Array: --> Int)
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 [42;3;70]).elems; # OUTPUT: «42»try [-∞...∞].elems;say $!.^name; # OUTPUT: «X::Cannot::Lazy»
class Supply
From Supply
(Supply) method elems
method elems(Supply: ? --> Supply)
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.
class Any
From Any
(Any) method elems
Defined as:
multi method elems(Any: --> 1)multi method elems(Any:)
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.
class Map
From Map
(Map) method elems
Defined as:
method elems(Map: --> Int)
Returns the number of pairs stored in the Map.
my = Map.new('a', 1, 'b', 2);say .elems; # OUTPUT: «2»
class Capture
From Capture
(Capture) method elems
Defined as:
method elems(Capture: --> Int)
Returns the number of positional elements in the Capture.
my Capture = \(2, 3, 5, apples => (red => 2));say .elems; # OUTPUT: «3»
class Uni
From Uni
(Uni) method elems
method elems(Uni: --> Int)
Returns the number of codepoints in the invocant.
class List
From List
(List) routine elems
Defined as:
sub elems( --> Int)method elems(List: --> Int)
Returns the number of elements in the list.
say (1,2,3,4).elems; # OUTPUT: «4»
role Blob
From Blob
(Blob) method elems
Defined as:
multi method elems(Blob:)multi method elems(Blob: --> 1)
Returns the number of elements of the buffer.
my = Blob.new([1, 2, 3]);say .elems; # OUTPUT: «3»
It will also return 1 on the class object.
class Metamodel::EnumHOW
From Metamodel::EnumHOW
(Metamodel::EnumHOW) method elems
method elems()
Returns the number of values.
<10 20>;say Numbers.^elems; # OUTPUT: 2