txt: ## positionalbindfailover.md
  role PositionalBindFailover
  
  Failover for binding to a Positional
  
  ```raku
  role PositionalBindFailover { ... }
  ```
  
  This role provides an interface by which an object can be coerced into a [`Positional`](/type/Positional) when binding to [`Positional`](/type/Positional) parameters.
  
  For example, [`Seq`](/type/Seq) type is not [`Positional`](/type/Positional), but you can still write the following, because it [does](/routine/does) `PositionalBindFailover` role:
  
  ```raku
  sub fifths(@a) {        # @a is constraint to Positional
      @a[4];
  }
  my $seq := gather {     # a Seq, which is not Positional
      take $_ for 1..*;
  }
  say fifths($seq);       # OUTPUT: «5␤»
  ```
  
  The invocation of `fifths` in the example above would ordinarily give a type error, because `$seq` is of type [`Seq`](/type/Seq), which doesn't do the [`Positional`](/type/Positional) interface that the `@`-sigil implies.
  
  But the signature binder recognizes that [`Seq`](/type/Seq) does the `PositionalBindFailover` role, and calls its `cache` method to coerce it to a [`List`](/type/List), which does the [`Positional`](/type/Positional) role.
  
  The same happens with custom classes that do the role; they simply need to provide an `iterator` method that produces an [`Iterator`](/type/Iterator):
  
  ```raku
  class Foo does PositionalBindFailover {
      method iterator {
          class :: does Iterator {
              method pull-one {
                  return 42 unless $++;
                  IterationEnd
              }
          }.new
      }
  }
  
  sub first-five (@a) { @a[^5].say }
  first-five Foo.new; # OUTPUT: # OUTPUT: «(42 Nil Nil Nil Nil)␤»
  ```
  
  # [Methods](#role_PositionalBindFailover "go to top of document")[§](#Methods "direct link")
  
  ## [method cache](#role_PositionalBindFailover "go to top of document")[§](#method_cache "direct link")
  
  ```raku
  method cache(PositionalBindFailover:D: --> List:D)
  ```
  
  Returns a [`List`](/type/List) based on the `iterator` method, and caches it. Subsequent calls to `cache` always return the same [`List`](/type/List) object.
  
  ## [method list](#role_PositionalBindFailover "go to top of document")[§](#method_list "direct link")
  
  ```raku
  multi method list(::?CLASS:D:)
  ```
  
  Returns a [`List`](/type/List) based on the `iterator` method without caching it.
  
  ## [method iterator](#role_PositionalBindFailover "go to top of document")[§](#method_iterator "direct link")
  
  ```raku
  method iterator(PositionalBindFailover:D:) { ... }
  ```
  
  This method stub ensure that a class implementing role `PositionalBindFailover` provides an `iterator` method.
  
  # [Typegraph](# "go to top of document")[§](#typegraphrelations "direct link")
  
  Type relations for `PositionalBindFailover`
  
  
  
  raku-type-graph
  
  
  
  PositionalBindFailover
  PositionalBindFailover
  
  
  Sequence
  Sequence
  
  
  Sequence->PositionalBindFailover
  
  
  
  Mu
  Mu
  
  
  Any
  Any
  
  
  Any->Mu
  
  
  
  Iterable
  Iterable
  
  
  RaceSeq
  RaceSeq
  
  
  RaceSeq->Sequence
  
  
  
  RaceSeq->Any
  
  
  
  RaceSeq->Iterable
  
  
  
  Cool
  Cool
  
  
  Cool->Any
  
  
  
  Seq
  Seq
  
  
  Seq->Sequence
  
  
  
  Seq->Iterable
  
  
  
  Seq->Cool
  
  
  
  HyperSeq
  HyperSeq
  
  
  HyperSeq->Sequence
  
  
  
  HyperSeq->Any
  
  
  
  HyperSeq->Iterable
  
  [Expand chart above](/assets/typegraphs/PositionalBindFailover.svg)
  