New definitions #
Computes the "bag intersection" of l₁
and l₂
, that is,
the collection of elements of l₁
which are also in l₂
. As each element
is identified, it is removed from l₂
, so elements are counted with multiplicity.
Equations
Instances For
after p xs
is the suffix of xs
after the first element that satisfies
p
, not including that element.
after (· == 1) [0, 1, 2, 3] = [2, 3]
drop_while (· != 1) [0, 1, 2, 3] = [1, 2, 3]
Equations
- List.after p [] = []
- List.after p (a :: l) = bif p a then l else List.after p l
Instances For
Replaces the first element of the list for which f
returns some
with the returned value.
Equations
- List.replaceF f [] = []
- List.replaceF f (a :: l) = match f a with | none => a :: List.replaceF f l | some a => a :: l
Instances For
Tail-recursive version of replaceF
.
Equations
- List.replaceFTR f l = List.replaceFTR.go f l #[]
Instances For
Auxiliary for replaceFTR
: replaceFTR.go f xs acc = acc.toList ++ replaceF f xs
.
Equations
- List.replaceFTR.go f [] x✝ = x✝.toList
- List.replaceFTR.go f (x_2 :: xs) x✝ = match f x_2 with | none => List.replaceFTR.go f xs (x✝.push x_2) | some a' => x✝.toListAppend (a' :: xs)
Instances For
Constructs the union of two lists, by inserting the elements of l₁
in reverse order to l₂
.
As a result, l₂
will always be a suffix, but only the last occurrence of each element in l₁
will be retained (but order will otherwise be preserved).
Equations
- l₁.union l₂ = List.foldr List.insert l₂ l₁
Instances For
Equations
- List.instUnionOfBEq_batteries = { union := List.union }
Equations
- List.instInterOfBEq_batteries = { inter := List.inter }
Split a list at an index. Ensures the left list always has the specified length by right padding with the provided default element.
splitAtD 2 [a, b, c] x = ([a, b], [c])
splitAtD 4 [a, b, c] x = ([a, b, c, x], [])
Equations
- List.splitAtD n l dflt = List.splitAtD.go dflt n l []
Instances For
Auxiliary for splitAtD
: splitAtD.go dflt n l acc = (acc.reverse ++ left, right)
if splitAtD n l dflt = (left, right)
.
Equations
- List.splitAtD.go dflt n.succ (x_3 :: xs) x✝ = List.splitAtD.go dflt n xs (x_3 :: x✝)
- List.splitAtD.go dflt 0 x✝¹ x✝ = (x✝.reverse, x✝¹)
- List.splitAtD.go dflt x✝¹ [] x✝ = (x✝.reverseAux (List.replicate x✝¹ dflt), [])
Instances For
Split a list at every element satisfying a predicate. The separators are not in the result.
[1, 1, 2, 3, 2, 4, 4].splitOnP (· == 2) = [[1, 1], [3], [4, 4]]
Equations
- List.splitOnP P l = List.splitOnP.go P l []
Instances For
Auxiliary for splitOnP
: splitOnP.go xs acc = res'
where res'
is obtained from splitOnP P xs
by prepending acc.reverse
to the first element.
Equations
Instances For
Tail recursive version of splitOnP
.
Equations
- List.splitOnPTR P l = List.splitOnPTR.go P l #[] #[]
Instances For
Auxiliary for splitOnP
: splitOnP.go xs acc r = r.toList ++ res'
where res'
is obtained from splitOnP P xs
by prepending acc.toList
to the first element.
Equations
- List.splitOnPTR.go P [] x✝¹ x✝ = x✝.toListAppend [x✝¹.toList]
- List.splitOnPTR.go P (a :: t) x✝¹ x✝ = bif P a then List.splitOnPTR.go P t #[] (x✝.push x✝¹.toList) else List.splitOnPTR.go P t (x✝¹.push a) x✝
Instances For
Split a list at every occurrence of a separator element. The separators are not in the result.
[1, 1, 2, 3, 2, 4, 4].splitOn 2 = [[1, 1], [3], [4, 4]]
Equations
- List.splitOn a as = List.splitOnP (fun (x : α) => x == a) as
Instances For
Alias of List.modifyTailIdx
.
Replaces the n
th tail of l
with the result of applying f
to it. Returns the input without
using f
if the index is larger than the length of the List.
Examples:
["circle", "square", "triangle"].modifyTailIdx 1 List.reverse
["circle", "triangle", "square"]
["circle", "square", "triangle"].modifyTailIdx 1 (fun xs => xs ++ xs)
["circle", "square", "triangle", "square", "triangle"]
["circle", "square", "triangle"].modifyTailIdx 2 (fun xs => xs ++ xs)
["circle", "square", "triangle", "triangle"]
["circle", "square", "triangle"].modifyTailIdx 5 (fun xs => xs ++ xs)
["circle", "square", "triangle"]
Equations
Instances For
Alias of List.modify
.
Replaces the element at the given index, if it exists, with the result of applying f
to it. If the
index is invalid, the list is returned unmodified.
Examples:
[1, 2, 3].modify 0 (· * 10) = [10, 2, 3]
[1, 2, 3].modify 2 (· * 10) = [1, 2, 30]
[1, 2, 3].modify 3 (· * 10) = [1, 2, 3]
Equations
Instances For
Apply f
to the last element of l
, if it exists.
Equations
- List.modifyLast f l = List.modifyLast.go f l #[]
Instances For
Auxiliary for modifyLast
: modifyLast.go f l acc = acc.toList ++ modifyLast f l
.
Equations
- List.modifyLast.go f [] x✝ = []
- List.modifyLast.go f [x_2] x✝ = x✝.toListAppend [f x_2]
- List.modifyLast.go f (x_2 :: xs) x✝ = List.modifyLast.go f xs (x✝.push x_2)
Instances For
Alias of List.insertIdx
.
Inserts an element into a list at the specified index. If the index is greater than the length of the list, then the list is returned unmodified.
In other words, the new element is inserted into the list l
after the first i
elements of l
.
Examples:
["tues", "thur", "sat"].insertIdx 1 "wed" = ["tues", "wed", "thur", "sat"]
["tues", "thur", "sat"].insertIdx 2 "wed" = ["tues", "thur", "wed", "sat"]
["tues", "thur", "sat"].insertIdx 3 "wed" = ["tues", "thur", "sat", "wed"]
["tues", "thur", "sat"].insertIdx 4 "wed" = ["tues", "thur", "sat"]
Equations
Instances For
Take n
elements from a list l
. If l
has less than n
elements, append n - length l
elements x
.
Equations
- List.takeD 0 x✝¹ x✝ = []
- List.takeD n.succ x✝¹ x✝ = x✝¹.headD x✝ :: List.takeD n x✝¹.tail x✝
Instances For
Tail-recursive version of takeD
.
Equations
- List.takeDTR n l dflt = List.takeDTR.go dflt n l #[]
Instances For
Auxiliary for takeDTR
: takeDTR.go dflt n l acc = acc.toList ++ takeD n l dflt
.
Equations
- List.takeDTR.go dflt n.succ (x_3 :: xs) x✝ = List.takeDTR.go dflt n xs (x✝.push x_3)
- List.takeDTR.go dflt 0 x✝¹ x✝ = x✝.toList
- List.takeDTR.go dflt x✝¹ [] x✝ = x✝.toListAppend (List.replicate x✝¹ dflt)
Instances For
Fold a function f
over the list from the left, returning the list of partial results.
scanl (+) 0 [1, 2, 3] = [0, 1, 3, 6]
Equations
- List.scanl f a [] = [a]
- List.scanl f a (a_1 :: l) = a :: List.scanl f (f a a_1) l
Instances For
Tail-recursive version of scanl
.
Equations
- List.scanlTR f a l = List.scanlTR.go f l a #[]
Instances For
Auxiliary for scanlTR
: scanlTR.go f l a acc = acc.toList ++ scanl f a l
.
Equations
- List.scanlTR.go f [] x✝¹ x✝ = x✝.toListAppend [x✝¹]
- List.scanlTR.go f (b :: l) x✝¹ x✝ = List.scanlTR.go f l (f x✝¹ b) (x✝.push x✝¹)
Instances For
Fold a function f
over the list from the right, returning the list of partial results.
scanr (+) 0 [1, 2, 3] = [6, 5, 3, 0]
Equations
Instances For
Fold a list from left to right as with foldl
, but the combining function
also receives each element's index.
Equations
- List.foldlIdx f init [] x✝ = init
- List.foldlIdx f init (b :: l) x✝ = List.foldlIdx f (f x✝ init b) l (x✝ + 1)
Instances For
Fold a list from right to left as with foldr
, but the combining function
also receives each element's index.
Equations
- List.foldrIdx f init [] x✝ = init
- List.foldrIdx f init (b :: l) x✝ = f x✝ b (List.foldrIdx f init l (x✝ + 1))
Instances For
Returns the elements of l
that satisfy p
together with their indexes in
l
. The returned list is ordered by index.
Equations
Instances For
indexesOf a l
is the list of all indexes of a
in l
. For example:
indexesOf a [a, b, a, a] = [0, 2, 3]
Equations
- List.indexesOf a = List.findIdxs fun (x : α) => x == a
Instances For
lookmap
is a combination of lookup
and filterMap
.
lookmap f l
will apply f : α → Option α
to each element of the list,
replacing a → b
at the first value a
in the list such that f a = some b
.
Equations
- List.lookmap f l = List.lookmap.go f l #[]
Instances For
Auxiliary for lookmap
: lookmap.go f l acc = acc.toList ++ lookmap f l
.
Equations
- List.lookmap.go f [] x✝ = x✝.toList
- List.lookmap.go f (x_2 :: xs) x✝ = match f x_2 with | some b => x✝.toListAppend (b :: xs) | none => List.lookmap.go f xs (x✝.push x_2)
Instances For
Auxiliary for tailsTR
: tailsTR.go l acc = acc.toList ++ tails l
.
Equations
- List.tailsTR.go [] acc = acc.toListAppend [[]]
- List.tailsTR.go (a :: l_1) acc = List.tailsTR.go l_1 (acc.push (a :: l_1))
Instances For
sublists' l
is the list of all (non-contiguous) sublists of l
.
It differs from sublists
only in the order of appearance of the sublists;
sublists'
uses the first element of the list as the MSB,
sublists
uses the first element of the list as the LSB.
sublists' [1, 2, 3] = [[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]]
Equations
Instances For
A version of List.sublists
that has faster runtime performance but worse kernel performance
Equations
- One or more equations did not get rendered due to their size.
Instances For
Forall₂ R l₁ l₂
means that l₁
and l₂
have the same length,
and whenever a
is the nth element of l₁
, and b
is the nth element of l₂
,
then R a b
is satisfied.
- nil
{α : Type u_1}
{β : Type u_2}
{R : α → β → Prop}
: Forall₂ R [] []
Two nil lists are
Forall₂
-related - cons {α : Type u_1} {β : Type u_2} {R : α → β → Prop} {a : α} {b : β} {l₁ : List α} {l₂ : List β} : R a b → Forall₂ R l₁ l₂ → Forall₂ R (a :: l₁) (b :: l₂)
Instances For
Check for all elements a
, b
, where a
and b
are the nth element of the first and second
List respectively, that r a b = true
.
Equations
Instances For
Equations
- l₁.instDecidableForall₂ l₂ = decidable_of_iff (List.all₂ (fun (x1 : α) (x2 : β) => decide (R x1 x2)) l₁ l₂ = true) ⋯
Transpose of a list of lists, treated as a matrix.
transpose [[1, 2], [3, 4], [5, 6]] = [[1, 3, 5], [2, 4, 6]]
Equations
Instances For
go : List α → Array (List α) → Array (List α)
handles the insertion of
a new list into all the lists in the array:
go [a, b, c] #[l₁, l₂, l₃] = #[a::l₁, b::l₂, c::l₃]
.
If the new list is too short, the later lists are unchanged, and if it is too long
the array is extended:
go [a] #[l₁, l₂, l₃] = #[a::l₁, l₂, l₃]
go [a, b, c, d] #[l₁, l₂, l₃] = #[a::l₁, b::l₂, c::l₃, [d]]
Equations
- List.transpose.go l acc = match Array.mapM List.transpose.pop acc l with | (acc, l) => List.foldl (fun (arr : Array (List α)) (a : α) => arr.push [a]) acc l
Instances For
List of all sections through a list of lists. A section
of [L₁, L₂, ..., Lₙ]
is a list whose first element comes from
L₁
, whose second element comes from L₂
, and so on.
Equations
Instances For
Optimized version of sections
.
Equations
- L.sectionsTR = bif L.any List.isEmpty then [] else (List.foldr List.sectionsTR.go #[[]] L).toList
Instances For
go : List α → Array (List α) → Array (List α)
inserts one list into the accumulated
list of sections acc
: go [a, b] #[l₁, l₂] = [a::l₁, b::l₁, a::l₂, b::l₂]
.
Equations
- List.sectionsTR.go l acc = Array.foldl (fun (acc' : Array (List α)) (l' : List α) => List.foldl (fun (acc' : Array (List α)) (a : α) => acc'.push (a :: l')) acc' l) #[] acc
Instances For
extractP p l
returns a pair of an element a
of l
satisfying the predicate
p
, and l
, with a
removed. If there is no such element a
it returns (none, l)
.
Equations
- List.extractP p l = List.extractP.go p l l #[]
Instances For
Auxiliary for extractP
:
extractP.go p l xs acc = (some a, acc.toList ++ out)
if extractP p xs = (some a, out)
,
and extractP.go p l xs acc = (none, l)
if extractP p xs = (none, _)
.
Equations
- List.extractP.go p l [] x✝ = (none, l)
- List.extractP.go p l (x_2 :: xs) x✝ = bif p x_2 then (some x_2, x✝.toListAppend xs) else List.extractP.go p l xs (x✝.push x_2)
Instances For
sigma l₁ l₂
is the list of dependent pairs (a, b)
where a ∈ l₁
and b ∈ l₂ a
.
sigma [1, 2] (λ_, [(5 : Nat), 6]) = [(1, 5), (1, 6), (2, 5), (2, 6)]
Equations
- l₁.sigma l₂ = List.flatMap (fun (a : α) => List.map (Sigma.mk a) (l₂ a)) l₁
Instances For
Optimized version of sigma
.
Equations
- l₁.sigmaTR l₂ = (List.foldl (fun (acc : Array ((a : α) × σ a)) (a : α) => List.foldl (fun (acc : Array ((a : α) × σ a)) (b : σ a) => acc.push ⟨a, b⟩) acc (l₂ a)) #[] l₁).toList
Instances For
ofFnNthVal f i
returns some (f i)
if i < n
and none
otherwise.
Equations
- List.ofFnNthVal f i = if h : i < n then some (f ⟨i, h⟩) else none
Instances For
Returns the longest initial prefix of two lists such that they are pairwise related by R
.
takeWhile₂ (· < ·) [1, 2, 4, 5] [5, 4, 3, 6] = ([1, 2], [5, 4])
Equations
Instances For
Tail-recursive version of takeWhile₂
.
Equations
- List.takeWhile₂TR R as bs = List.takeWhile₂TR.go R as bs [] []
Instances For
Auxiliary for takeWhile₂TR
:
takeWhile₂TR.go R as bs acca accb = (acca.reverse ++ as', acca.reverse ++ bs')
if takeWhile₂ R as bs = (as', bs')
.
Equations
Instances For
Chain R a l
means that R
holds between adjacent elements of a::l
.
Chain R a [b, c, d] ↔ R a b ∧ R b c ∧ R c d
- nil
{α : Type u_1}
{R : α → α → Prop}
{a : α}
: Chain R a []
A chain of length 1 is trivially a chain.
- cons
{α : Type u_1}
{R : α → α → Prop}
{a b : α}
{l : List α}
: R a b → Chain R b l → Chain R a (b :: l)
If
a
relates tob
andb::l
is a chain, thena :: b :: l
is also a chain.
Instances For
Chain' R l
means that R
holds between adjacent elements of l
.
Chain' R [a, b, c, d] ↔ R a b ∧ R b c ∧ R c d
Equations
- List.Chain' R [] = True
- List.Chain' R (a :: l) = List.Chain R a l
Instances For
eraseDup l
removes duplicates from l
(taking only the first occurrence).
Defined as pwFilter (≠)
.
eraseDup [1, 0, 2, 2, 1] = [0, 2, 1]
Equations
- List.eraseDup = List.pwFilter fun (x1 x2 : α) => (x1 != x2) = true
Instances For
mapDiagM f l
calls f
on all elements in the upper triangular part of l × l
.
That is, for each e ∈ l
, it will run f e e
and then f e e'
for each e'
that appears after e
in l
.
mapDiagM f [1, 2, 3] =
return [← f 1 1, ← f 1 2, ← f 1 3, ← f 2 2, ← f 2 3, ← f 3 3]
Equations
- List.mapDiagM f l = List.mapDiagM.go f l #[]
Instances For
Auxiliary for mapDiagM
: mapDiagM.go as f acc = (acc.toList ++ ·) <$> mapDiagM f as
Equations
- List.mapDiagM.go f [] x✝ = pure x✝.toList
- List.mapDiagM.go f (x_2 :: xs) x✝ = do let b ← f x_2 x_2 let acc ← List.foldlM (fun (x1 : Array β) (x2 : α) => x1.push <$> f x_2 x2) (x✝.push b) xs List.mapDiagM.go f xs acc
Instances For
forDiagM f l
calls f
on all elements in the upper triangular part of l × l
.
That is, for each e ∈ l
, it will run f e e
and then f e e'
for each e'
that appears after e
in l
.
forDiagM f [1, 2, 3] = do f 1 1; f 1 2; f 1 3; f 2 2; f 2 3; f 3 3
Equations
- List.forDiagM f [] = pure PUnit.unit
- List.forDiagM f (a :: l) = do f a a l.forM (f a) List.forDiagM f l
Instances For
getRest l l₁
returns some l₂
if l = l₁ ++ l₂
.
If l₁
is not a prefix of l
, returns none
Equations
Instances For
List.dropSlice n m xs
removes a slice of length m
at index n
in list xs
.
Equations
- List.dropSlice x✝¹ x✝ [] = []
- List.dropSlice 0 x✝¹ x✝ = List.drop x✝¹ x✝
- List.dropSlice n.succ x✝ (x_3 :: xs) = x_3 :: List.dropSlice n x✝ xs
Instances For
Optimized version of dropSlice
.
Equations
- List.dropSliceTR n 0 l = l
- List.dropSliceTR n m_2.succ l = List.dropSliceTR.go l m_2 l n #[]
Instances For
Auxiliary for dropSliceTR
: dropSliceTR.go l m xs n acc = acc.toList ++ dropSlice n m xs
unless n ≥ length xs
, in which case it is l
.
Equations
- List.dropSliceTR.go l m [] x✝¹ x✝ = l
- List.dropSliceTR.go l m (head :: xs) 0 x✝ = x✝.toListAppend (List.drop m xs)
- List.dropSliceTR.go l m (x_3 :: xs) n.succ x✝ = List.dropSliceTR.go l m xs n (x✝.push x_3)
Instances For
Left-biased version of List.zipWith
. zipWithLeft' f as bs
applies f
to each
pair of elements aᵢ ∈ as
and bᵢ ∈ bs
. If bs
is shorter than as
, f
is
applied to none
for the remaining aᵢ
. Returns the results of the f
applications and the remaining bs
.
zipWithLeft' prod.mk [1, 2] ['a'] = ([(1, some 'a'), (2, none)], [])
zipWithLeft' prod.mk [1] ['a', 'b'] = ([(1, some 'a')], ['b'])
Equations
Instances For
Tail-recursive version of zipWithLeft'
.
Equations
- List.zipWithLeft'TR f as bs = List.zipWithLeft'TR.go f as bs #[]
Instances For
Auxiliary for zipWithLeft'TR
: zipWithLeft'TR.go l acc = acc.toList ++ zipWithLeft' l
.
Equations
Instances For
Right-biased version of List.zipWith
. zipWithRight' f as bs
applies f
to each
pair of elements aᵢ ∈ as
and bᵢ ∈ bs
. If as
is shorter than bs
, f
is
applied to none
for the remaining bᵢ
. Returns the results of the f
applications and the remaining as
.
zipWithRight' prod.mk [1] ['a', 'b'] = ([(some 1, 'a'), (none, 'b')], [])
zipWithRight' prod.mk [1, 2] ['a'] = ([(some 1, 'a')], [2])
Equations
- List.zipWithRight' f as bs = List.zipWithLeft' (flip f) bs as
Instances For
Left-biased version of List.zip
. zipLeft' as bs
returns the list of
pairs (aᵢ, bᵢ)
for aᵢ ∈ as
and bᵢ ∈ bs
. If bs
is shorter than as
, the
remaining aᵢ
are paired with none
. Also returns the remaining bs
.
zipLeft' [1, 2] ['a'] = ([(1, some 'a'), (2, none)], [])
zipLeft' [1] ['a', 'b'] = ([(1, some 'a')], ['b'])
zipLeft' = zipWithLeft' prod.mk
Equations
Instances For
Right-biased version of List.zip
. zipRight' as bs
returns the list of
pairs (aᵢ, bᵢ)
for aᵢ ∈ as
and bᵢ ∈ bs
. If as
is shorter than bs
, the
remaining bᵢ
are paired with none
. Also returns the remaining as
.
zipRight' [1] ['a', 'b'] = ([(some 1, 'a'), (none, 'b')], [])
zipRight' [1, 2] ['a'] = ([(some 1, 'a')], [2])
zipRight' = zipWithRight' prod.mk
Equations
Instances For
Left-biased version of List.zipWith
. zipWithLeft f as bs
applies f
to each pair
aᵢ ∈ as
and bᵢ ∈ bs∈ bs
. If bs
is shorter than as
, f
is applied to none
for the remaining aᵢ
.
zipWithLeft prod.mk [1, 2] ['a'] = [(1, some 'a'), (2, none)]
zipWithLeft prod.mk [1] ['a', 'b'] = [(1, some 'a')]
zipWithLeft f as bs = (zipWithLeft' f as bs).fst
Equations
Instances For
Tail-recursive version of zipWithLeft
.
Equations
- List.zipWithLeftTR f as bs = List.zipWithLeftTR.go f as bs #[]
Instances For
Auxiliary for zipWithLeftTR
: zipWithLeftTR.go l acc = acc.toList ++ zipWithLeft l
.
Equations
- List.zipWithLeftTR.go f [] x✝¹ x✝ = x✝.toList
- List.zipWithLeftTR.go f x✝¹ [] x✝ = (List.foldl (fun (acc : Array γ) (a : α) => acc.push (f a none)) x✝ x✝¹).toList
- List.zipWithLeftTR.go f (a :: as) (b :: bs) x✝ = List.zipWithLeftTR.go f as bs (x✝.push (f a (some b)))
Instances For
Right-biased version of List.zipWith
. zipWithRight f as bs
applies f
to each
pair aᵢ ∈ as
and bᵢ ∈ bs∈ bs
. If as
is shorter than bs
, f
is applied to
none
for the remaining bᵢ
.
zipWithRight prod.mk [1, 2] ['a'] = [(some 1, 'a')]
zipWithRight prod.mk [1] ['a', 'b'] = [(some 1, 'a'), (none, 'b')]
zipWithRight f as bs = (zipWithRight' f as bs).fst
Equations
- List.zipWithRight f as bs = List.zipWithLeft (flip f) bs as
Instances For
Left-biased version of List.zip
. zipLeft as bs
returns the list of pairs
(aᵢ, bᵢ)
for aᵢ ∈ as
and bᵢ ∈ bs
. If bs
is shorter than as
, the
remaining aᵢ
are paired with none
.
zipLeft [1, 2] ['a'] = [(1, some 'a'), (2, none)]
zipLeft [1] ['a', 'b'] = [(1, some 'a')]
zipLeft = zipWithLeft prod.mk
Equations
Instances For
Right-biased version of List.zip
. zipRight as bs
returns the list of pairs
(aᵢ, bᵢ)
for aᵢ ∈ as
and bᵢ ∈ bs
. If as
is shorter than bs
, the
remaining bᵢ
are paired with none
.
zipRight [1, 2] ['a'] = [(some 1, 'a')]
zipRight [1] ['a', 'b'] = [(some 1, 'a'), (none, 'b')]
zipRight = zipWithRight prod.mk
Equations
Instances For
Tail-recursive version of fillNones
.
Equations
- as.fillNonesTR as' = List.fillNonesTR.go as as' #[]
Instances For
Auxiliary for fillNonesTR
: fillNonesTR.go as as' acc = acc.toList ++ fillNones as as'
.
Equations
- List.fillNonesTR.go [] x✝¹ x✝ = x✝.toList
- List.fillNonesTR.go (some a :: as) x✝¹ x✝ = List.fillNonesTR.go as x✝¹ (x✝.push a)
- List.fillNonesTR.go (none :: as) [] x✝ = List.filterMapTR.go id as x✝
- List.fillNonesTR.go (none :: as) (a :: as') x✝ = List.fillNonesTR.go as as' (x✝.push a)
Instances For
takeList as ns
extracts successive sublists from as
. For ns = n₁ ... nₘ
,
it first takes the n₁
initial elements from as
, then the next n₂
ones,
etc. It returns the sublists of as
-- one for each nᵢ
-- and the remaining
elements of as
. If as
does not have at least as many elements as the sum of
the nᵢ
, the corresponding sublists will have less than nᵢ
elements.
takeList ['a', 'b', 'c', 'd', 'e'] [2, 1, 1] = ([['a', 'b'], ['c'], ['d']], ['e'])
takeList ['a', 'b'] [3, 1] = ([['a', 'b'], []], [])
Equations
Instances For
Auxiliary for takeListTR
: takeListTR.go as as' acc = acc.toList ++ takeList as as'
.
Equations
- List.takeListTR.go [] x✝¹ x✝ = (x✝.toList, x✝¹)
- List.takeListTR.go (n :: ns) x✝¹ x✝ = match List.splitAt n x✝¹ with | (xs₁, xs₂) => List.takeListTR.go ns xs₂ (x✝.push xs₁)
Instances For
Auxliary definition used to define toChunks
.
toChunksAux n xs i
returns (xs.take i, (xs.drop i).toChunks (n+1))
,
that is, the first i
elements of xs
, and the remaining elements chunked into
sublists of length n+1
.
Equations
Instances For
xs.toChunks n
splits the list into sublists of size at most n
,
such that (xs.toChunks n).join = xs
.
[1, 2, 3, 4, 5, 6, 7, 8].toChunks 10 = [[1, 2, 3, 4, 5, 6, 7, 8]]
[1, 2, 3, 4, 5, 6, 7, 8].toChunks 3 = [[1, 2, 3], [4, 5, 6], [7, 8]]
[1, 2, 3, 4, 5, 6, 7, 8].toChunks 2 = [[1, 2], [3, 4], [5, 6], [7, 8]]
[1, 2, 3, 4, 5, 6, 7, 8].toChunks 0 = [[1, 2, 3, 4, 5, 6, 7, 8]]
Equations
- List.toChunks x✝ [] = []
- List.toChunks 0 x✝ = [x✝]
- List.toChunks x✝ (x_2 :: xs) = List.toChunks.go x✝ xs #[x_2] #[]
Instances For
Auxliary definition used to define toChunks
.
toChunks.go xs acc₁ acc₂
pushes elements into acc₁
until it reaches size n
,
then it pushes the resulting list to acc₂
and continues until xs
is exhausted.
Equations
- List.toChunks.go n [] x✝¹ x✝ = (x✝.push x✝¹.toList).toList
- List.toChunks.go n (a :: t) x✝¹ x✝ = if (x✝¹.size == n) = true then List.toChunks.go n t ((Array.mkEmpty n).push a) (x✝.push x✝¹.toList) else List.toChunks.go n t (x✝¹.push a) x✝
Instances For
We add some n-ary versions of List.zipWith
for functions with more than two arguments.
These can also be written in terms of List.zip
or List.zipWith
.
For example, zipWith₃ f xs ys zs
could also be written as
zipWith id (zipWith f xs ys) zs
or as
(zip xs <| zip ys zs).map fun ⟨x, y, z⟩ => f x y z
.
Ternary version of List.zipWith
.
Equations
- List.zipWith₃ f (x_3 :: xs) (y :: ys) (z :: zs) = f x_3 y z :: List.zipWith₃ f xs ys zs
- List.zipWith₃ f x✝² x✝¹ x✝ = []
Instances For
Quaternary version of List.zipWith
.
Equations
- List.zipWith₄ f (x_4 :: xs) (y :: ys) (z :: zs) (u :: us) = f x_4 y z u :: List.zipWith₄ f xs ys zs us
- List.zipWith₄ f x✝³ x✝² x✝¹ x✝ = []
Instances For
Quinary version of List.zipWith
.
Equations
- List.zipWith₅ f (x_5 :: xs) (y :: ys) (z :: zs) (u :: us) (v :: vs) = f x_5 y z u v :: List.zipWith₅ f xs ys zs us vs
- List.zipWith₅ f x✝⁴ x✝³ x✝² x✝¹ x✝ = []
Instances For
An auxiliary function for List.mapWithPrefixSuffix
.
Equations
- List.mapWithPrefixSuffixAux f x✝ [] = []
- List.mapWithPrefixSuffixAux f x✝ (a :: l₂) = f x✝ a l₂ :: List.mapWithPrefixSuffixAux f (x✝.concat a) l₂
Instances For
List.mapWithPrefixSuffix f l
maps f
across a list l
.
For each a ∈ l
with l = pref ++ [a] ++ suff
, a
is mapped to f pref a suff
.
Example: if f : list Nat → Nat → list Nat → β
,
List.mapWithPrefixSuffix f [1, 2, 3]
will produce the list
[f [] 1 [2, 3], f [1] 2 [3], f [1, 2] 3 []]
.
Equations
Instances For
List.mapWithComplement f l
is a variant of List.mapWithPrefixSuffix
that maps f
across a list l
.
For each a ∈ l
with l = pref ++ [a] ++ suff
, a
is mapped to f a (pref ++ suff)
,
i.e., the list input to f
is l
with a
removed.
Example: if f : Nat → list Nat → β
, List.mapWithComplement f [1, 2, 3]
will produce the list
[f 1 [2, 3], f 2 [1, 3], f 3 [1, 2]]
.
Equations
- List.mapWithComplement f = List.mapWithPrefixSuffix fun (pref : List α) (a : α) (suff : List α) => f a (pref ++ suff)
Instances For
Map each element of a List
to an action, evaluate these actions in order,
and collect the results.
Equations
- List.traverse f [] = pure []
- List.traverse f (a :: l) = List.cons <$> f a <*> List.traverse f l
Instances For
Subperm l₁ l₂
, denoted l₁ <+~ l₂
, means that l₁
is a sublist of
a permutation of l₂
. This is an analogue of l₁ ⊆ l₂
which respects
multiplicities of elements, and is used for the ≤
relation on multisets.
Instances For
Subperm l₁ l₂
, denoted l₁ <+~ l₂
, means that l₁
is a sublist of
a permutation of l₂
. This is an analogue of l₁ ⊆ l₂
which respects
multiplicities of elements, and is used for the ≤
relation on multisets.
Equations
- List.«term_<+~_» = Lean.ParserDescr.trailingNode `List.«term_<+~_» 50 50 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " <+~ ") (Lean.ParserDescr.cat `term 51))
Instances For
O(|l₁| * (|l₁| + |l₂|))
. Computes whether l₁
is a sublist of a permutation of l₂
.
See isSubperm_iff
for a characterization in terms of List.Subperm
.
Equations
- l₁.isSubperm l₂ = decide (∀ (x : α), x ∈ l₁ → List.count x l₁ ≤ List.count x l₂)
Instances For
O(|l|)
. Inserts a
in l
right before the first element such that p
is true, or at the end of
the list if p
always false on l
.
Equations
- List.insertP p a l = List.insertP.loop p a l []
Instances For
Inner loop for insertP
. Tail recursive.
Equations
- List.insertP.loop p a [] x✝ = (a :: x✝).reverseAux []
- List.insertP.loop p a (a_1 :: t) x✝ = bif p a_1 then (a :: x✝).reverseAux (a_1 :: t) else List.insertP.loop p a t (a_1 :: x✝)
Instances For
dropPrefix? l p
returns
some r
if l = p' ++ r
for some p'
which is paiwise ==
to p
,
and none
otherwise.
Equations
Instances For
dropSuffix? l s
returns
some r
if l = r ++ s'
for some s'
which is paiwise ==
to s
,
and none
otherwise.
Equations
Instances For
dropInfix? l i
returns
some (p, s)
if l = p ++ i' ++ s
for some i'
which is paiwise ==
to i
,
and none
otherwise.
Note that this is an inefficient implementation, and if computation time is a concern you should be
using the Knuth-Morris-Pratt algorithm as implemented in Batteries.Data.List.Matcher
.
Equations
- l.dropInfix? i = List.dropInfix?.go i l []
Instances For
Inner loop for dropInfix?
.