Documentation

Init.Data.Slice.Array.Iterator

This module implements an iterator for array slices (Subarray).

@[unbox]
structure SubarrayIterator (α : Type u) :
Instances For
    @[inline]
    def SubarrayIterator.step {α : Type u} {m : Type u → Type u_1} :
    Equations
      Instances For
        instance instForInSubarrayOfMonad {α : Type u} {m : Type v → Type w} [Monad m] :
        ForIn m (Subarray α) α
        Equations

          Without defining the following function Subarray.foldlM, it is still possible to call subarray.foldlM, which would be elaborated to Slice.foldlM (s := subarray). However, in order to maximize backward compatibility and avoid confusion in the manual entry for Subarray, we explicitly provide the wrapper function Subarray.foldlM for Slice.foldlM, providing a more specific docstring.

          @[inline]
          def Subarray.foldlM {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (f : βαm β) (init : β) (as : Subarray α) :
          m β

          Folds a monadic operation from left to right over the elements in a subarray. An accumulator of type β is constructed by starting with init and monadically combining each element of the subarray with the current accumulator value in turn. The monad in question may permit early termination or repetition. Examples:

          #eval #["red", "green", "blue"].toSubarray.foldlM (init := "") fun acc x => do
            let l ← Option.guard (· ≠ 0) x.length
            return s!"{acc}({l}){x} "
          
          some "(3)red (5)green (4)blue "
          
          #eval #["red", "green", "blue"].toSubarray.foldlM (init := 0) fun acc x => do
            let l ← Option.guard (· ≠ 5) x.length
            return s!"{acc}({l}){x} "
          
          none
          
          Equations
            Instances For
              @[inline]
              def Subarray.foldl {α : Type u} {β : Type v} (f : βαβ) (init : β) (as : Subarray α) :
              β

              Folds an operation from left to right over the elements in a subarray. An accumulator of type β is constructed by starting with init and combining each element of the subarray with the current accumulator value in turn. Examples:

              • #["red", "green", "blue"].toSubarray.foldl (· + ·.length) 0 = 12
              • #["red", "green", "blue"].toSubarray.popFront.foldl (· + ·.length) 0 = 9
              Equations
                Instances For
                  @[inline]
                  def Subarray.forIn {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (s : Subarray α) (b : β) (f : αβm (ForInStep β)) :
                  m β

                  The implementation of ForIn.forIn for Subarray, which allows it to be used with for loops in do-notation.

                  Equations
                    Instances For
                      def Subarray.toArray {α : Type u} (s : Subarray α) :

                      Allocates a new array that contains the contents of the subarray.

                      Equations
                        Instances For
                          instance instCoeSubarrayArray {α : Type u} :
                          Coe (Subarray α) (Array α)
                          Equations
                            def Subarray.copy {α : Type u} (s : Subarray α) :

                            Allocates a new array that contains the contents of the subarray.

                            Equations
                              Instances For
                                @[simp]
                                theorem Subarray.copy_eq_toArray {α : Type u} {s : Subarray α} :
                                s.copy = s
                                def Array.ofSubarray {α : Type u} (s : Subarray α) :

                                Allocates a new array that contains the contents of the subarray.

                                Equations
                                  Instances For
                                    Equations
                                      def Array.Subarray.repr {α : Type u} [Repr α] (s : Subarray α) :

                                      Subarray representation.

                                      Equations
                                        Instances For
                                          instance Array.instReprSubarray {α : Type u} [Repr α] :
                                          Equations
                                            Equations