This role provides an interface by which an object can be coerced into a Positional when binding to Positional parameters.
For example, Seq type is not Positional, but you can still write the following, because it does PositionalBindFailover
role:
sub fifths() my := gather say fifths(); # OUTPUT: «5»
The invocation of fifths
in the example above would ordinarily give a type error, because $seq
is of type Seq, which doesn't do the Positional interface that the @
-sigil implies.
But the signature binder recognizes that Seq
does the PositionalBindFailover
role, and calls its cache
method to coerce it to a List, which does the Positional
role.
The same happens with custom classes that do the role; they simply need to provide an iterator
method that produces an Iterator:
does PositionalBindFailover sub first-five () first-five Foo.new; # OUTPUT: # OUTPUT: «(42 Nil Nil Nil Nil)»
Methods §
method cache §
method cache(PositionalBindFailover: --> List)
Returns a List based on the iterator
method, and caches it. Subsequent calls to cache
always return the same List
object.
method list §
multi method list(::?CLASS:)
Returns a List based on the iterator
method without caching it.
method iterator §
method iterator(PositionalBindFailover:)
This method stub ensure that a class implementing role PositionalBindFailover
provides an iterator
method.