Documentation

Init.Data.Slice.Operations

@[implicit_reducible]
instance Std.Slice.instToIterator {γ : Type u_1} {m : Type u_2 → Type u_3} {α β : Type u_2} [ToIterator γ m α β] :
ToIterator (Slice γ) m α β
@[inline]
def Std.Slice.Internal.iter {γ : Type u_1} {α β : Type u_2} [ToIterator (Slice γ) Id α β] (s : Slice γ) :
Iter β

Internal function to obtain an iterator from a slice. Users should import Std.Data.Iterators and use Std.Slice.iter instead.

Instances For
    class Std.Slice.SliceSize (γ : Type u) :

    This type class provides support for the Slice.size function.

    Instances
      class Std.Slice.LawfulSliceSize {α β : Type u_1} (γ : Type u) [SliceSize γ] [ToIterator (Slice γ) Id α β] [Iterator α Id β] :

      This type class states that the slice's iterator emits exactly Slice.size elements before terminating.

      Instances
        @[inline]
        def Std.Slice.size {γ : Type u_1} (s : Slice γ) [SliceSize γ] :

        Returns the number of elements with distinct indices in the given slice.

        Example: #[1, 1, 1][0...2].size = 2.

        Instances For
          @[inline]
          def Std.Slice.toArray {γ : Type u_1} {α β : Type u_2} [ToIterator (Slice γ) Id α β] [Iterator α Id β] (s : Slice γ) :

          Allocates a new array that contains the elements of the slice.

          Instances For
            @[inline]
            def Std.Slice.toList {γ : Type u_1} {α β : Type u_2} [ToIterator (Slice γ) Id α β] [Iterator α Id β] (s : Slice γ) :
            List β

            Allocates a new list that contains the elements of the slice.

            Instances For
              @[inline]
              def Std.Slice.toListRev {γ : Type u_1} {α β : Type u_2} [ToIterator (Slice γ) Id α β] [Iterator α Id β] (s : Slice γ) :
              List β

              Allocates a new list that contains the elements of the slice in reverse order.

              Instances For
                @[implicit_reducible]
                instance Std.Slice.instForInOfMonadOfToIteratorOfIteratorLoopId {m : Type u_1 → Type u_2} {α : Type v} {γ : Type u} {β : Type v} [Monad m] [ToIterator (Slice γ) Id α β] [Iterator α Id β] [IteratorLoop α Id m] :
                ForIn m (Slice γ) β
                @[inline]
                def Std.Slice.foldlM {α : Type v} {γ : Type u} {β : Type v} {δ : Type w} {m : Type w → Type w'} [Monad m] (f : δβm δ) (init : δ) [ToIterator (Slice γ) Id α β] [Iterator α Id β] [IteratorLoop α Id m] (s : Slice γ) :
                m δ

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

                Examples for the special case of subarrays:

                #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
                
                Instances For
                  @[inline]
                  def Std.Slice.foldl {α : Type v} {γ : Type u} {β : Type v} {δ : Type w} (f : δβδ) (init : δ) [ToIterator (Slice γ) Id α β] [Iterator α Id β] [IteratorLoop α Id Id] (s : Slice γ) :
                  δ

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

                  • #["red", "green", "blue"].toSubarray.foldl (· + ·.length) 0 = 12
                  • #["red", "green", "blue"].toSubarray.popFront.foldl (· + ·.length) 0 = 9
                  Instances For