txt: ## sequence.md
  role Sequence
  
  Common methods of sequences
  
  ```raku
  role Sequence does PositionalBindFailover { }
  ```
  
  This role implements a series of methods for converting sequences and accessing their elements. These methods should work on all sequences: serial [`Seq`](/type/Seq), ordered parallel [`HyperSeq`](/type/HyperSeq), and unordered parallel [`RaceSeq`](/type/RaceSeq).
  
  These methods have in common that they all access the underlying iterator if the sequence has not been [cached](/type/PositionalBindFailover#method_cache) yet. Therefore they will throw an error of type [`X::Seq::Consumed`](/type/X/Seq/Consumed) if called on a [`Seq`](/type/Seq) that was already consumed.
  
  # [Methods](#role_Sequence "go to top of document")[§](#Methods "direct link")
  
  ## [method Str](#role_Sequence "go to top of document")[§](#method_Str "direct link")
  
  ```raku
  multi method Str(::?CLASS:D:)
  ```
  
  [Stringifies](/type/List#method_Str) the [cached](/type/PositionalBindFailover#method_cache) sequence.
  
  ## [method Stringy](#role_Sequence "go to top of document")[§](#method_Stringy "direct link")
  
  ```raku
  multi method Stringy(::?CLASS:D:)
  ```
  
  Calls `.Stringy` on the [cached](/type/PositionalBindFailover#method_cache) sequence.
  
  ## [method Numeric](#role_Sequence "go to top of document")[§](#method_Numeric "direct link")
  
  ```raku
  method Numeric(::?CLASS:D:)
  ```
  
  Returns the number of elements in the [cached](/type/PositionalBindFailover#method_cache) sequence.
  
  ## [method AT-POS](#role_Sequence "go to top of document")[§](#method_AT-POS "direct link")
  
  ```raku
  multi method AT-POS(::?CLASS:D: Int:D $idx)
  multi method AT-POS(::?CLASS:D: int $idx)
  ```
  
  Returns the element at position `$idx` in the [cached](/type/PositionalBindFailover#method_cache) sequence.
  
  ## [method EXISTS-POS](#role_Sequence "go to top of document")[§](#method_EXISTS-POS "direct link")
  
  ```raku
  multi method EXISTS-POS(::?CLASS:D: Int:D $idx)
  multi method EXISTS-POS(::?CLASS:D: int $idx)
  ```
  
  Returns a [`Bool`](/type/Bool) indicating whether there is an element at position `$idx` in the [cached](/type/PositionalBindFailover#method_cache) sequence.
  
  ## [method eager](#role_Sequence "go to top of document")[§](#method_eager "direct link")
  
  ```raku
  method eager(::?CLASS:D: --> List:D)
  ```
  
  Returns an eagerly evaluated [`List`](/type/List) based on the invocant sequence, and marks it as consumed. If called on an already consumed [`Seq`](/type/Seq), throws an error of type [`X::Seq::Consumed`](/type/X/Seq/Consumed).
  
  ```raku
  my $s = lazy 1..5;
  
  say $s.is-lazy; # OUTPUT: «True␤»
  say $s.eager;   # OUTPUT: «(1 2 3 4 5)␤»
  
  say $s.eager;
  CATCH {
      when X::Seq::Consumed {
          say 'Throws exception if already consumed';
      }
  }
  # OUTPUT: «Throws exception if already consumed␤»
  ```
  
  ## [method fmt](#role_Sequence "go to top of document")[§](#method_fmt "direct link")
  
  ```raku
  method fmt($format = '%s', $separator = ' ' --> Str:D)
  ```
  
  [Formats](/type/List#method_fmt) the [cached](/type/PositionalBindFailover#method_cache) sequence.
  
  ## [method gist](#role_Sequence "go to top of document")[§](#method_gist "direct link")
  
  ```raku
  multi method gist(::?CLASS:D:)
  ```
  
  Returns the [gist](/type/List#method_gist) of the [cached](/type/PositionalBindFailover#method_cache) sequence.
  
  # [Typegraph](# "go to top of document")[§](#typegraphrelations "direct link")
  
  Type relations for `Sequence`
  
  
  
  raku-type-graph
  
  
  
  Sequence
  Sequence
  
  
  PositionalBindFailover
  PositionalBindFailover
  
  
  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/Sequence.svg)
  