Documentation

Init.Data.Slice.List.Basic

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

Internal representation of ListSlice, which is an abbreviation for Slice ListSliceData.

  • list : List α

    The relevant suffix of the underlying list.

  • stop : Option Nat

    The maximum length of the slice, starting at the beginning of list.

Instances
    @[reducible, inline]
    abbrev ListSlice (α : Type u) :

    A region of some underlying list. List slices can be used to avoid copying or allocating space, while being more convenient than tracking the bounds by hand.

    A list slice only stores the suffix of the underlying list, starting from the range's lower bound so that the cost of operations on the slice does not depend on the start position. However, the cost of creating a list slice is linear in the start position.

    Equations
    Instances For
      def List.toSlice {α : Type u} (as : List α) (start stop : Nat) :

      Returns a slice of a list with the given bounds.

      If start or stop are not valid bounds for a sublist, then they are clamped to the list's length. Additionally, the starting index is clamped to the ending index.

      This function is linear in start because it stores as.drop start in the slice.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        def List.toUnboundedSlice {α : Type u} (as : List α) (start : Nat) :

        Returns a slice of a list with the given lower bound.

        If start is not a valid bound for a sublist, then they are clamped to the list's length.

        This function is linear in start because it stores as.drop start in the slice.

        Equations
        Instances For
          Equations
          Equations
          Equations
          Equations
          Equations
          Equations
          Equations
          Equations