Skip to content

Commit 6031380

Browse files
committed
Document .are($type)
1 parent 415ddcf commit 6031380

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

doc/Type/Any.rakudoc

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,15 @@ method called on it.
718718
=head2 method are
719719

720720
multi method are(Any:)
721+
multi method are(Any: Any $type)
721722

722-
Returns the strictest type (or role) to which B<all> elements of the list
723-
will smartmatch. Returns L<C<Nil>|/type/Nil> on an empty list.
723+
The argumentless version available as of release 2022.02 of the Rakudo
724+
compiler. The version with the type argument is in the 6.e language version
725+
(early implementation exists in Rakudo compiler 2024.05+).
726+
727+
If called without arguments, returns the strictest type (or role) to which
728+
B<all> elements of the list will smartmatch. Returns L<C<Nil>|/type/Nil>
729+
on an empty list.
724730

725731
say (1,2,3).are; # OUTPUT: «(Int)␤»
726732
say <a b c>.are; # OUTPUT: «(Str)␤»
@@ -736,14 +742,29 @@ Scalar values are interpreted as a single element list.
736742
say Int.are; # OUTPUT: «(Int)␤»
737743

738744
Hashes will be interpreted as a list of pairs, and as such will always
739-
produce the L<C<Pair>|/type/Pair> type object. Use the C<.keys> or C<.values> method
740-
to get the strictest type of the keys or the values of a hash.
745+
produce the L<C<Pair>|/type/Pair> type object. Use the C<.keys> or
746+
C<.values> method to get the strictest type of the keys or the values of
747+
a hash.
741748

742749
my %h = a => 42, b => "bar";
743750
say %h.keys.are; # OUTPUT: «(Str)␤»
744751
say %h.values.are; # OUTPUT: «(Cool)␤»
745752

746-
Available as of release 2022.02 of the Rakudo compiler.
753+
If called with a type argument, will check if all types in the invocant
754+
smartmatch with the given type. If so, returns C<True>. If any of the
755+
smartmatches fails, returns a C<Failure>
756+
757+
say (1,2,3).are(Int); # OUTPUT: «True␤»
758+
say <a b c>.are(Str); # OUTPUT: «True␤»
759+
say <42 666>.are(Int); # OUTPUT: «True␤»
760+
say <42 666>.are(Str); # OUTPUT: «True␤»
761+
say (42,666e0).are(Real); # OUTPUT: «True␤»
762+
say (42,i).are(Numeric); # OUTPUT: «True␤»
763+
say ("a",42,3.14).are(Cool); # OUTPUT: «True␤»
764+
say ().are; # OUTPUT: «True␤»
765+
766+
Int.are(Str); # OUTPUT: «Expected 'Str' but got 'Int'␤»
767+
(1,2,3).are(Str); # OUTPUT: «Expected 'Str' but got 'Int' in element 0␤»
747768

748769
=head2 method prepend
749770

0 commit comments

Comments
 (0)