In List§

See primary documentation in context for method fmt

method fmt($format = '%s', $separator = ' ' --> Str:D)

Returns a string where each element in the list has been formatted according to $format and where each element is separated by $separator. If the list contains nested sub-lists, then fmt will flatten them before formatting each element. Thus, fmt will treat [1, 2, [3, 4]] as a list with 4 elements rather than 3.

For more information about formats strings, see sprintf.

my @a = 8..11;
say @a.fmt('%03d', ',');  # OUTPUT: «008,009,010,011␤»

In Pair§

See primary documentation in context for method fmt

multi method fmt(Pair:D: Str:D $format --> Str:D)

Takes a format string, and returns a string the key and value parts of the Pair formatted. Here's an example:

my $pair = :Earth(1);
say $pair.fmt("%s is %.3f AU away from the sun")
# OUTPUT: «Earth is 1.000 AU away from the sun␤»

For more about format strings, see sprintf.

In role Sequence§

See primary documentation in context for method fmt

method fmt($format = '%s', $separator = ' ' --> Str:D)

Formats the cached sequence.

In Cool§

See primary documentation in context for method fmt

method fmt($format = '%s')

Uses $format to return a formatted representation of the invocant; equivalent to calling sprintf with $format as format and the invocant as the second argument. The $format will be coerced to Stringy and defaults to '%s'.

For more information about formats strings, see sprintf.

say 11.fmt('This Int equals %03d');         # OUTPUT: «This Int equals 011␤»
say '16'.fmt('Hexadecimal %x');             # OUTPUT: «Hexadecimal 10␤»

In Range§

See primary documentation in context for method fmt

method fmt(|c)

Returns a string where min and max in the Range have been formatted according to |c.

For more information about parameters, see List.fmt.

say (1..2).fmt("Element: %d", ",") # OUTPUT: «Element: 1,Element: 2␤»