class Whatever
ErrorsCollection

class Whatever

Placeholder for the value of an unspecified argument

class Whatever { }

Whatever is a class whose objects don't have any explicit meaning; it gets its semantics from other routines that accept Whatever-objects as markers to do something special. Using the * literal as an operand creates a Whatever object.

Much of *'s charm comes from Whatever-currying. When * is used in term position, that is, as an operand, in combination with most operators, the compiler will transform the expression into a closure of type WhateverCode, which is actually a Block that can be used wherever Callables are accepted.

my $c = * + 2;          # same as   -> $x { $x + 2 }; 
say $c(4);              # OUTPUT: «6␤»

Multiple * in one expression generate closures with as many arguments:

my $c = * + *;          # same as   -> $x, $y { $x + $y }

Using * in complex expressions will also generate closures:

my $c = 4 * * + 5;      # same as   -> $x { 4 * $x + 5 }

Calling a method on * also creates a closure:

<a b c>.map: *.uc;      # same as    <a b c>.map: -> $char { $char.uc } 

As mentioned before, not all operators and syntactic constructs curry * (or Whatever-stars) to WhateverCode. In the following cases, * will remain a Whatever object.

ExceptionExampleWhat it does
comma1, *, 2generates a List with a * element
range operators1 .. *Range.new(:from(1), :to(*));
series operator1 ... *infinite list
assignment$x = *assign * to $x
binding$x := *bind * to $x
list repetition1 xx *generates an infinite list

The range operators are handled specially. They do not curry with Whatever-stars, but they do curry with WhateverCode

say (1..*).^name;       # OUTPUT: «Range␤» 
say ((1..*-1)).^name;   # OUTPUT: «WhateverCode␤»

This allows all these constructs to work:

.say for 1..*;          # infinite loop 

and

my @a = 1..4;
say @a[0..*];           # OUTPUT: «(1 2 3 4)␤» 
say @a[0..*-2];         # OUTPUT: «(1 2 3)␤»

Because Whatever-currying is a purely syntactic compiler transform, you will get no runtime currying of stored Whatever-stars into WhateverCodes.

my $x = *;
$x + 2;   # Not a closure, dies because it can't coerce $x to Numeric 
CATCH { default { put .^name''.Str } };
# OUTPUT: «X::Multi::NoMatch: Cannot resolve caller Numeric(Whatever: ); 
# none of these signatures match:␤ 
# (Mu:U \v: *%_)» 

The use cases for stored Whatever-stars involve those curry-exception cases mentioned above. For example, if you want an infinite series by default.

my $max    = potential-upper-limit() // *;
my $series = known-lower-limit() ... $max;

A stored * will also result in the generation of a WhateverCode in the specific case of smartmatch. Note that this is not actually the stored * which is being curried, but rather the * on the left-hand side.

my $constraint           = find-constraint() // *;
my $maybe-always-matcher = * ~~ $constraint;

If this hypothetical find-constraint were to have found no constraint, $maybe-always-matcher would evaluate to True for anything.

$maybe-always-matcher(555);      # True 
$maybe-always-matcher(Any);      # True 

HyperWhatever's functionality is similar to Whatever, except it refers to multiple values, instead of a single one.

Methods

method ACCEPTS

multi method ACCEPTS(Whatever:D: Mu $other)
multi method ACCEPTS(Whatever:U: Mu $other)

If the invocant is an instance, always returns True. If the invocant is a type object, performs a typecheck.

say 42 ~~ (*);       # OUTPUT: «True␤» 
say 42 ~~ Whatever;  # OUTPUT: «False␤»

method Capture

method Capture()

Throws X::Cannot::Capture.