Skip to content

Commit fd229dc

Browse files
committed
Any.first edited, with some explanations added. Closes #2877
1 parent 5181c55 commit fd229dc

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

doc/Type/Any.pod6

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -777,11 +777,11 @@ In general, coerces the invocant to a C<list> by applying its
777777
L«C<.list>|/routine/list» method and uses
778778
L«C<List.first>|/type/List#routine_first» on it.
779779
780-
However, there are several different methods, and they have (slightly) different
781-
behavior. Using a C<Bool> as the argument will always return a L<Failure>. Using
782-
it as a subroutine is equivalent to using it as a method with the second
783-
argument as the object.
780+
However, this is a multi with different signatures, which are implemented with
781+
(slightly) different behavior, although using it as a subroutine is equivalent
782+
to using it as a method with the second argument as the object.
784783
784+
For starters, using a C<Bool> as the argument will always return a L<Failure>.
785785
The form that uses a C<$test> will return the first element that smartmatches
786786
it, starting from the end if C<:end> is used.
787787
@@ -791,19 +791,23 @@ it, starting from the end if C<:end> is used.
791791
say first 0xF, (⅓,⅔…30); # OUTPUT: «15␤»
792792
say (3..33).first( /\d\d/ ); # OUTPUT: «10␤»
793793
794-
The third and fourth example use the C<Mu $test> forms which smartmatches and
794+
The third and fourth examples use the C<Mu $test> forms which smartmatches and
795795
returns the first element that does. The last example uses as a test a regex for
796796
numbers with two figures, and thus the first that meets that criterion is number
797797
10. This last form uses the C<Callable> multi:
798798
799799
say (⅓,⅔…30).first( * %% 11, :end, :kv ); # OUTPUT: «(65 22)␤»
800800
801+
Besides, the search for first will start from the C<:end> and returns the set of
802+
key/values in a list; the I<key> in this case is simply the position it occupies
803+
in the C<Seq>. The C<:kv> argument, which is part of the C<%a> argument in the
804+
definitions above, modifies what C<first> returns, providing it as a flattened list of keys and values; for a listy object, the key will always be the index.
805+
801806
From version 6.d, the test can also be a C<Junction>:
802807
803808
say (⅓,⅔…30).first( 3 | 33, :kv ); # OUTPUT: «(8 3)␤»
804809
805-
Besides, starts from the C<:end> and returns the C<:kv> in a list; the I<key> in
806-
this case is simply the position it occupies in the C<Seq>.
810+
807811
808812
=head2 method unique
809813

0 commit comments

Comments
 (0)