Documentation

Hale.Base.Data.List

def Data.List'.nubBy {α : Type u_1} (eq : ααBool) (l : List α) :
List α

Remove duplicate elements, preserving first occurrence, using a custom equality. $$\text{nubBy}(eq, [x_1, \ldots, x_n])$$ keeps $x_i$ if no earlier $x_j$ satisfies $\text{eq}(x_j, x_i)$.

Equations
Instances For
    def Data.List'.nubBy.go {α : Type u_1} (eq : ααBool) :
    List αList αList α
    Equations
    Instances For
      def Data.List'.nub {α : Type u_1} [BEq α] (l : List α) :
      List α

      Remove duplicate elements using BEq, preserving first occurrence. $$\text{nub} = \text{nubBy}(\text{BEq.beq})$$

      Equations
      Instances For
        @[irreducible]
        def Data.List'.groupBy {α : Type u_1} (eq : ααBool) :
        List αList (List α)

        Group consecutive equal elements by a custom equality. $$\text{groupBy}(eq, [a, a, b, b, b, a]) = [[a, a], [b, b, b], [a]]$$

        Equations
        Instances For
          def Data.List'.group {α : Type u_1} [BEq α] (l : List α) :
          List (List α)

          Group consecutive equal elements using BEq. $$\text{group} = \text{groupBy}(\text{BEq.beq})$$

          Equations
          Instances For
            def Data.List'.transpose {α : Type u_1} (xss : List (List α)) :
            List (List α)

            Transpose a list of lists (rows to columns). $$\text{transpose}([[1,2,3],[4,5,6]]) = [[1,4],[2,5],[3,6]]$$ Uses fuel-based termination.

            Equations
            Instances For
              def Data.List'.transpose.go {α : Type u_1} :
              List (List α)NatList (List α)
              Equations
              Instances For
                def Data.List'.tails {α : Type u_1} :
                List αList.NonEmpty (List α)

                All suffixes, from longest to shortest, including []. Returns NonEmpty since every list has at least the empty suffix. $$\text{tails}([1,2,3]) = [[1,2,3],[2,3],[3],[]]$$

                Equations
                Instances For
                  def Data.List'.inits {α : Type u_1} :
                  List αList.NonEmpty (List α)

                  All prefixes, from shortest to longest. Returns NonEmpty since every list has at least the empty prefix. $$\text{inits}([1,2,3]) = [[],[1],[1,2],[1,2,3]]$$

                  Equations
                  Instances For
                    def Data.List'.subsequences {α : Type u_1} :
                    List αList (List α)

                    All subsequences (power set), including []. $$|\text{subsequences}(l)| = 2^{|l|}$$

                    Equations
                    Instances For
                      def Data.List'.permutations {α : Type u_1} :
                      List αList (List α)

                      All permutations of a list. $$|\text{permutations}(l)| = |l|!$$

                      Equations
                      Instances For
                        def Data.List'.unfoldr {β : Type u_1} {α : Type u_2} (f : βOption (α × β)) (seed : β) (fuel : Nat := 10000) :
                        List α

                        Build a list from a seed by repeatedly applying f. $$\text{unfoldr}(f, b_0) = [a_1, a_2, \ldots]$$ where $f(b_i) = \text{some}(a_{i+1}, b_{i+1})$ until $f(b_n) = \text{none}$. Fuel-limited to ensure termination.

                        Equations
                        Instances For
                          def Data.List'.scanr {α : Type u_1} {β : Type u_2} (f : αββ) (z : β) :

                          Right-to-left scan, producing all intermediate accumulators. Returns NonEmpty since the result always includes at least the initial accumulator z. $$\text{scanr}(f, z, [x_1, \ldots, x_n]) = [f(x_1, f(x_2, \ldots f(x_n, z))), \ldots, f(x_n, z), z]$$

                          Equations
                          Instances For
                            def Data.List'.mapAccumL {σ : Type u_1} {α : Type u_2} {β : Type u_3} (f : σασ × β) (init : σ) :
                            List ασ × List β

                            Left-to-right map with accumulator. $$\text{mapAccumL}(f, s_0, [x_1, \ldots, x_n]) = (s_n, [y_1, \ldots, y_n])$$ where $(s_i, y_i) = f(s_{i-1}, x_i)$.

                            Equations
                            Instances For
                              def Data.List'.mapAccumR {σ : Type u_1} {α : Type u_2} {β : Type u_3} (f : σασ × β) (init : σ) :
                              List ασ × List β

                              Right-to-left map with accumulator. $$\text{mapAccumR}(f, s_0, [x_1, \ldots, x_n]) = (s_n, [y_1, \ldots, y_n])$$ where processing goes right-to-left.

                              Equations
                              Instances For
                                def Data.List'.intercalate {α : Type u_1} (sep : List α) :
                                List (List α)List α

                                Intercalate: insert a separator between lists and flatten. $$\text{intercalate}(sep, [l_1, \ldots, l_n]) = l_1 \mathbin{++} sep \mathbin{++} l_2 \mathbin{++} \cdots \mathbin{++} l_n$$

                                Equations
                                Instances For
                                  def Data.List'.sortOn {β : Type u_1} {α : Type u_2} [Ord β] (f : αβ) (l : List α) :
                                  List α

                                  Sort by a derived key. $$\text{sortOn}(f, l)$$ sorts $l$ by comparing $f(x)$ values.

                                  Equations
                                  Instances For
                                    def Data.List'.maximumBy {α : Type u_1} (cmp : ααOrdering) :
                                    List αOption α

                                    Maximum element by a custom comparator, or none for empty lists. $$\text{maximumBy}(\text{cmp}, l)$$

                                    Equations
                                    Instances For
                                      def Data.List'.minimumBy {α : Type u_1} (cmp : ααOrdering) :
                                      List αOption α

                                      Minimum element by a custom comparator, or none for empty lists. $$\text{minimumBy}(\text{cmp}, l)$$

                                      Equations
                                      Instances For
                                        def Data.List'.deleteBy {α : Type u_1} (eq : ααBool) (x : α) :
                                        List αList α

                                        Delete the first occurrence matching the predicate. $$\text{deleteBy}(eq, x, l)$$ removes the first $y$ in $l$ with $\text{eq}(x, y)$.

                                        Equations
                                        Instances For
                                          def Data.List'.unionBy {α : Type u_1} (eq : ααBool) (xs ys : List α) :
                                          List α

                                          List union by a custom equality. $$\text{unionBy}(eq, l_1, l_2)$$ appends elements of $l_2$ not in $l_1$.

                                          Equations
                                          Instances For
                                            def Data.List'.intersectBy {α : Type u_1} (eq : ααBool) (xs ys : List α) :
                                            List α

                                            List intersection by a custom equality. $$\text{intersectBy}(eq, l_1, l_2)$$ keeps elements of $l_1$ that are in $l_2$.

                                            Equations
                                            Instances For
                                              def Data.List'.insertBy {α : Type u_1} (cmp : ααOrdering) (x : α) :
                                              List αList α

                                              Insert into a sorted list, maintaining order. $$\text{insertBy}(\text{cmp}, x, l)$$ places $x$ before the first element greater than it.

                                              Equations
                                              Instances For
                                                @[inline]
                                                def Data.List'.genericLength {α : Type u_1} (l : List α) :

                                                genericLength is List.length in Lean (which already returns Nat). $$\text{genericLength}(l) = |l|$$

                                                Equations
                                                Instances For
                                                  theorem Data.List'.tails_length {α : Type u_1} (l : List α) :

                                                  The tails function produces length + 1 suffixes (as a NonEmpty). $$|\text{tails}(l).\text{toList}| = |l| + 1$$

                                                  theorem Data.List'.inits_length {α : Type u_1} (l : List α) :

                                                  The inits function produces length + 1 prefixes (as a NonEmpty). $$|\text{inits}(l).\text{toList}| = |l| + 1$$

                                                  tails of the empty list is the singleton [[]].

                                                  inits of the empty list is the singleton [[]].