method Numeric

Documentation for method Numeric, assembled from the following types:

class List

From List

(List) method Numeric

Defined as:

method Numeric(List:D: --> Int:D)

Returns the number of elements in the list (same as .elems).

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

enum Bool

From Bool

(Bool) routine Numeric

multi method Numeric(Bool:D --> Int:D)

Returns the value part of the enum pair.

say False.Numeric;                                # OUTPUT: «0␤» 
say True.Numeric;                                 # OUTPUT: «1␤» 

class Capture

From Capture

(Capture) method Numeric

Defined as:

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

Returns the number of positional elements in the Capture.

say \(1,2,3apples => 2).Numeric;                # OUTPUT: «3␤» 

class Str

From Str

(Str) method Numeric

Defined as:

method Numeric(Str:D: --> Numeric:D)

Coerces the string to Numeric. Fails with X::Str::Numeric if the coercion cannot be done.

Only Unicode characters with property Nd, as well as leading and trailing whitespace are allowed, with the special case of the empty string being coerced to 0. Synthetic codepoints (e.g. "7\x[308]") are forbidden.

While Nl and No characters can be used as numeric literals in the language, their conversion via Str.Numeric will fail, by design. See unival if you need to coerce such characters to Numeric.

class ComplexStr

From ComplexStr

(ComplexStr) method Numeric

method Numeric

The numeric coercion is applied when the ComplexStr is used in a numeric context, such as a numeric comparison or smart match against a numeric value. It will return the Complex value.

class Map

From Map

(Map) method Numeric

Defined as:

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

Returns the number of pairs stored in the Map (same as .elems).

my $m = Map.new('a' => 2'b' => 17);
say $m.Numeric;                                   # OUTPUT: «2␤» 

class IO::Path

From IO::Path

(IO::Path) method Numeric

Defined as:

method Numeric(IO::Path:D: --> Numeric:D)

Coerces .basename to Numeric. Fails with X::Str::Numeric if base name is not numerical.

class IntStr

From IntStr

(IntStr) method Numeric

method Numeric

The numeric coercion is applied when the IntStr is used in a numeric context, such as a numeric comparison or smart match against a numeric value. It will return the Int value.

class Nil

From Nil

(Nil) method Numeric

method Numeric()

Warns the user that they tried to numify a Nil.

class NumStr

From NumStr

(NumStr) method Numeric

method Numeric

The numeric coercion is applied when the NumStr is used in a numeric context, such as a numeric comparison or smart match against a numeric value. It will return the Num value.

class RatStr

From RatStr

(RatStr) method Numeric

method Numeric

The numeric coercion is applied when the RatStr is used in a numeric context, such as a numeric comparison or smart match against a numeric value. It will return the Rat value.

class Thread

From Thread

(Thread) method Numeric

method Numeric(Thread:D: --> Int:D)

Returns a numeric, unique thread identifier, i.e. the same as id.