Skip to content

Commit e390f35

Browse files
committed
Adds reduce, refs #1731
1 parent 048d6e0 commit e390f35

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

doc/Type/Any.pod6

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ function.
900900
my @years = (2003..2008).map( { Date.new( $_~"-01-01" ) } );
901901
@years.classify( *.is-leap-year , into => my %leap-years );
902902
say %leap-years;
903-
# OUTPUT: «{False => [2003-01-01 2005-01-01 2006-01-01 2007-01-01],
903+
# OUTPUT: «{False => [2003-01-01 2005-01-01 2006-01-01 2007-01-01],
904904
# True => [2004-01-01 2008-01-01]}␤»
905905
906906
@@ -909,6 +909,22 @@ normalized by the C<Callable> passed with the C<:as> argument, and it can use
909909
the C<:into> named argument to pass a C<Hash> the results will be classified
910910
into; in the example above, it's defined on the fly.
911911
912+
=head2 method reduce
913+
914+
Defined as:
915+
916+
multi method reduce(Any:U: & --> Nil)
917+
multi method reduce(Any:D: &with)
918+
multi sub reduce (&with, +list)
919+
920+
Applying it to a class will always produce Nil.
921+
Applies its argument (or first argument, in case it's a sub) as an operator to
922+
all the elements in the object (or second argument), producing a single result.
923+
The argument must be an infix operator or take, in any case, two positional
924+
arguments.
925+
926+
(1..13).reduce( &[*] ).say; # OUTPUT: «6227020800␤»
927+
912928
=head2 method produce
913929
914930
Defined as:

0 commit comments

Comments
 (0)