In Any§
See primary documentation in context for method are.
multi method are(Any:) multi method are(Any: Any $type)
The argumentless version available as of release 2022.02 of the Rakudo compiler. The version with the type argument is in the 6.e language version (early implementation exists in Rakudo compiler 2024.05+).
If called without arguments, returns the strictest type (or role) to which all elements of the list will smartmatch. Returns Nil on an empty list.
say (1,2,3).are; # OUTPUT: «(Int)» say <a b c>.are; # OUTPUT: «(Str)» say <42 666>.are; # OUTPUT: «(IntStr)» say (42,666e0).are; # OUTPUT: «(Real)» say (42,i).are; # OUTPUT: «(Numeric)» say ("a",42,3.14).are; # OUTPUT: «(Cool)» say ().are; # OUTPUT: «Nil»
Scalar values are interpreted as a single element list.
say 42.are; # OUTPUT: «(Int)» say Int.are; # OUTPUT: «(Int)»
Hashes will be interpreted as a list of pairs, and as such will always produce the Pair type object. Use the .keys or .values method to get the strictest type of the keys or the values of a hash.
my %h = a => 42, b => "bar"; say %h.keys.are; # OUTPUT: «(Str)» say %h.values.are; # OUTPUT: «(Cool)»
If called with a type argument, will check if all types in the invocant smartmatch with the given type. If so, returns True. If any of the smartmatches fails, returns a Failure.
say (1,2,3).are(Int); # OUTPUT: «True» say <a b c>.are(Str); # OUTPUT: «True» say <42 666>.are(Int); # OUTPUT: «True» say <42 666>.are(Str); # OUTPUT: «True» say (42,666e0).are(Real); # OUTPUT: «True» say (42,i).are(Numeric); # OUTPUT: «True» say ("a",42,3.14).are(Cool); # OUTPUT: «True» say ().are; # OUTPUT: «True» Int.are(Str); # OUTPUT: «Expected 'Str' but got 'Int'» (1,2,3).are(Str); # OUTPUT: «Expected 'Str' but got 'Int' in element 0»