Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adds reduce, refs #1731
  • Loading branch information
JJ committed Feb 19, 2019
1 parent 048d6e0 commit e390f35
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion doc/Type/Any.pod6
Expand Up @@ -900,7 +900,7 @@ function.
my @years = (2003..2008).map( { Date.new( $_~"-01-01" ) } );
@years.classify( *.is-leap-year , into => my %leap-years );
say %leap-years;
# OUTPUT: «{False => [2003-01-01 2005-01-01 2006-01-01 2007-01-01],
# OUTPUT: «{False => [2003-01-01 2005-01-01 2006-01-01 2007-01-01],
# True => [2004-01-01 2008-01-01]}␤»
Expand All @@ -909,6 +909,22 @@ normalized by the C<Callable> passed with the C<:as> argument, and it can use
the C<:into> named argument to pass a C<Hash> the results will be classified
into; in the example above, it's defined on the fly.
=head2 method reduce
Defined as:
multi method reduce(Any:U: & --> Nil)
multi method reduce(Any:D: &with)
multi sub reduce (&with, +list)
Applying it to a class will always produce Nil.
Applies its argument (or first argument, in case it's a sub) as an operator to
all the elements in the object (or second argument), producing a single result.
The argument must be an infix operator or take, in any case, two positional
arguments.
(1..13).reduce( &[*] ).say; # OUTPUT: «6227020800␤»
=head2 method produce
Defined as:
Expand Down

0 comments on commit e390f35

Please sign in to comment.