Rand Stats

The uploading author of github:alabamenhu does not match the META author of zef:guifa.




A module for formatting lists in a localized manner

To format lists using this module, use the provided sub C:

format-list @list

There are three named options available:


If your language is set to English…

my @list = <apples oranges bananas>;
say format-list @list;              # 'apples, oranges, and bananas'
say format-list @list, :type<or>;   # 'apples, oranges, or bananas'
say format-list @list, :type<unit>; # 'apples, oranges, bananas'

But if your language is set to Spanish…

my $a = 'manzanas';
my $o = 'naranjas';
my $b = 'plátanos';
say format-list $a, $o, $b;            # 'manzanas, naranjas y plátanos'
say format-list $a, $o, $b, :type<or>; # 'manzanas, naranjas o plátanos'
say format-list $a, $o, $b, :type<unit; # 'manzanas, naranjas y plátanos'

As you can tell, the format-list sub follows the single-argument rule, allowing either a list proper or an inline list of items. All items passed in are stringified.

For developers

If you want to integrate the list formatter via RakuAST, you can obtain a Callable (currently a RakuAST::PointyBlock) by the following:

use Intl::Format::List :rakuast;
my $formatter-ast = format-list-rakuast('en', 'and', 'standard')

Presently, all three parameters (language, type, length) must be specified.

Version history

© 2020–2022 Matthew Stephen Stuckwisch. Licensed under Artistic License 2.0