Skip to content

Commit ff5c3df

Browse files
committed
First attempt at writing documentation for the new operators
1 parent 2cd9794 commit ff5c3df

File tree

4 files changed

+110
-5
lines changed

4 files changed

+110
-5
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: 23 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pod/perlfunc.pod

Lines changed: 62 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,67 @@ 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<all> feature|feature/"The '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::all> unless that category is silenced.
839+
840+
=item any BLOCK LIST
841+
842+
=for Pod::Functions test if at least one value in a list satisfies the given condition
843+
844+
Evaluates the BLOCK for each element of the LIST (locally setting
845+
L<C<$_>|perlvar/$_> to each element) and checks the truth of the result of
846+
that block. Returns true if at least one element makes the block yield
847+
true, or returns false if no element is found to make it true.
848+
849+
As soon as any element makes the block yield true, then the result of this
850+
operator is determined. It will short-circuit in that case and not consider
851+
any further elements.
852+
853+
When used as a condition, this is similar to L<C<grep>|/grep BLOCK LIST>,
854+
except for this short-circuit behaviour.
855+
856+
if( any { length $_ } @strings ) {
857+
say "At least one string is non-empty";
858+
}
859+
860+
is roughly equivalent to
861+
862+
if( grep { length $_ } @strings ) ...
863+
864+
This operator is only available if the
865+
L<C<any> feature|feature/"The 'any' feature"> is enabled.
866+
867+
It is currently considered B<experimental>, and will issue a compile-time
868+
warning in the category C<experimental::any> unless that category is silenced.
869+
808870
=item atan2 Y,X
809871
X<atan2> X<arctangent> X<tan> X<tangent>
810872

regen/feature.pl

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,11 +985,32 @@ =head2 The 'apostrophe_as_package_separator' feature
985985
986986
=head2 The 'any' feature
987987
988-
TODO write some docs
988+
B<WARNING>: This feature is still experimental and the implementation may
989+
change or be removed in future versions of Perl. For this reason, Perl will
990+
warn when you use the feature, unless you have explicitly disabled the warning:
991+
992+
no warnings "experimental::any";
993+
994+
This feature enables the L<C<any>|perlfunc/any BLOCK LIST> operator keyword.
995+
This allow testing whether any of the values in a list satisfy a given
996+
condition, with short-circuiting behaviour as soon as it finds one.
989997
990998
=head2 The 'all' feature
991999
992-
TODO write some docs
1000+
B<WARNING>: This feature is still experimental and the implementation may
1001+
change or be removed in future versions of Perl. For this reason, Perl will
1002+
warn when you use the feature, unless you have explicitly disabled the warning:
1003+
1004+
no warnings "experimental::all";
1005+
1006+
This feature enables the L<C<all>|perlfunc/all BLOCK LIST> operator keyword.
1007+
This allow testing whether all of the values in a list satisfy a given
1008+
condition, with short-circuiting behaviour as soon as it finds one that does
1009+
not.
1010+
1011+
B<Note:> remember that this enables one specific feature whose name is C<all>;
1012+
it does not enable all of the features. This is not C<use feature ':all'>.
1013+
For that, see the section below.
9931014
9941015
=head1 FEATURE BUNDLES
9951016

0 commit comments

Comments
 (0)