Skip to content

Commit a85ae40

Browse files
committed
First attempt at writing documentation for the new operators
1 parent df4f5f1 commit a85ae40

File tree

4 files changed

+86
-3
lines changed

4 files changed

+86
-3
lines changed

ext/Pod-Functions/t/Functions.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ Functions for real @ARRAYs:
9191
each, keys, pop, push, shift, splice, unshift, values
9292
9393
Functions for list data:
94-
grep, join, map, qw/STRING/, reverse, sort, unpack
94+
all, any, grep, join, map, qw/STRING/, reverse, sort,
95+
unpack
9596
9697
Functions for real %HASHes:
9798
delete, each, exists, keys, values

lib/feature.pm

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pod/perlfunc.pod

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ X<list>
173173

174174
=for Pod::Functions =LIST
175175

176+
L<C<all>|/all BLOCK LIST>, L<C<any>|/any BLOCK LIST>,
176177
L<C<grep>|/grep BLOCK LIST>, L<C<join>|/join EXPR,LIST>,
177178
L<C<map>|/map BLOCK LIST>, L<C<qwE<sol>E<sol>>|/qwE<sol>STRINGE<sol>>,
178179
L<C<reverse>|/reverse LIST>, L<C<sort>|/sort SUBNAME LIST>,
@@ -805,6 +806,69 @@ For more information see L<perlipc>.
805806

806807
Portability issues: L<perlport/alarm>.
807808

809+
=item all BLOCK LIST
810+
811+
=for Pod::Functions test if every value in a list satisfies the given condition
812+
813+
Evaluates the BLOCK for each element of the LIST (locally setting
814+
L<C<$_>|perlvar/$_> to each element) and checks the truth of the result of
815+
that block. Returns true if every element makes the block yield true, or
816+
returns false if at least one element makes the block false.
817+
818+
As soon as any element makes the block yield false, then the result of this
819+
operator is determined. It will short-circuit in that case and not consider
820+
any further elements.
821+
822+
When used as a condition, this is similar to using L<C<grep>|/grep BLOCK LIST>
823+
to count that every value satisfies the condition, except for this
824+
short-circuit behaviour.
825+
826+
if( all { length $_ } @strings ) {
827+
say "Every string is non-empty";
828+
}
829+
830+
is roughly equivalent to
831+
832+
if( @strings == grep { length $_ } @strings ) ...
833+
834+
This operator is only available if the
835+
L<C<any_all> feature|feature/"The 'any_all' feature"> is enabled.
836+
837+
It is currently considered B<experimental>, and will issue a compile-time
838+
warning in the category C<experimental::any_all> unless that category is
839+
silenced.
840+
841+
=item any BLOCK LIST
842+
843+
=for Pod::Functions test if at least one value in a list satisfies the given condition
844+
845+
Evaluates the BLOCK for each element of the LIST (locally setting
846+
L<C<$_>|perlvar/$_> to each element) and checks the truth of the result of
847+
that block. Returns true if at least one element makes the block yield
848+
true, or returns false if no element is found to make it true.
849+
850+
As soon as any element makes the block yield true, then the result of this
851+
operator is determined. It will short-circuit in that case and not consider
852+
any further elements.
853+
854+
When used as a condition, this is similar to L<C<grep>|/grep BLOCK LIST>,
855+
except for this short-circuit behaviour.
856+
857+
if( any { length $_ } @strings ) {
858+
say "At least one string is non-empty";
859+
}
860+
861+
is roughly equivalent to
862+
863+
if( grep { length $_ } @strings ) ...
864+
865+
This operator is only available if the
866+
L<C<any_all> feature|feature/"The 'any_all' feature"> is enabled.
867+
868+
It is currently considered B<experimental>, and will issue a compile-time
869+
warning in the category C<experimental::any_all> unless that category is
870+
silenced.
871+
808872
=item atan2 Y,X
809873
X<atan2> X<arctangent> X<tan> X<tangent>
810874

regen/feature.pl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,16 @@ =head2 The 'apostrophe_as_package_separator' feature
984984
985985
=head2 The 'any_all' feature
986986
987-
TODO write some docs
987+
B<WARNING>: This feature is still experimental and the implementation may
988+
change or be removed in future versions of Perl. For this reason, Perl will
989+
warn when you use the feature, unless you have explicitly disabled the warning:
990+
991+
no warnings "experimental::any_all";
992+
993+
This feature enables the L<C<any>|perlfunc/any BLOCK LIST> and
994+
L<C<all>|perlfunc/all BLOCK LIST> operator keywords. These allow testing
995+
whether values in a list satisfy a given condition, with short-circuiting
996+
behaviour.
988997
989998
=head1 FEATURE BUNDLES
990999

0 commit comments

Comments
 (0)