method default
Documentation for method default assembled from the following types:
role Baggy
From Baggy
(Baggy) method default
Defined as:
method default(Baggy: --> Int)
Returns zero.
my = bag <eggs bacon>;say .default; # OUTPUT: «0»
role Setty
From Setty
(Setty) method default
Defined as:
method default(--> False)
Returns the default value of the invocant, i.e. the value which is returned when trying to access an element in the Setty object which has not been previously initialized or when accessing an element which has explicitly been set to Nil or False.
my = SetHash.new(1, 2, 3);say ; # OUTPUT: «True»= Nil;say ; # OUTPUT: «False»# access non initialized elementsay ; # OUTPUT: «False»
class Parameter
From Parameter
(Parameter) method default
Returns a closure that upon invocation returns the default value for this parameter, or Any if no default was provided.
class Scalar
From Scalar
(Scalar) method default
method default(Scalar: --> Str)
Returns the default value associated with the container.
Example:
my is default(666) = 42;say .VAR.default; # OUTPUT: «666»
class Array
From Array
(Array) method default
Defined as:
method default
Returns the default value of the invocant, i.e. the value which is returned when trying to access an element in the Array which has not been previously initialized or when accessing an element which has explicitly been set to Nil. Unless the Array is declared as having a default value by using the is default trait the method returns the type object (Any).
my = 1, "two", 2.718;say .default; # OUTPUT: «(Any)»say [4]; # OUTPUT: «(Any)»my is default(17) = 1, "two", 3;say .default; # OUTPUT: «17»say [4]; # OUTPUT: «17»[1] = Nil; # (resets element to its default)say [1]; # OUTPUT: «17»
class Hash
From Hash
(Hash) method default
Defined as:
method default()
Returns the default value of the invocant, i.e. the value which is returned when a non existing key is used to access an element in the Hash. Unless the Hash is declared as having a default value by using the is default trait the method returns the type object (Any).
my = 'apples' => 3, 'oranges' => 7;say .default; # OUTPUT: «(Any)»say ; # OUTPUT: «(Any)»my is default(1) = 'apples' => 3, 'oranges' => 7;say .default; # OUTPUT: «1»say + ; # OUTPUT: «4»