Documentation

Init.Data.Slice.Array.Iterator

This module provides slice notation for array slices (a.k.a. Subarray) and implements an iterator for those slices.

Equations
  • One or more equations did not get rendered due to their size.
instance instForInSubarray {α : Type u} {m : Type v → Type w} :
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 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
            def Subarray.toArray {α : Type u} (s : Subarray α) :

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

            Equations
            Instances For