Dropping or taking from lists on the right #
Taking or removing element from the tail end of a list
Main definitions #
rdrop n: dropn : ℕelements from the tailrtake n: taken : ℕelements from the tailrdropWhile p: remove all the elements from the tail of a list until it finds the first element for whichp : α → Boolreturns false. This element and everything before is returned.rtakeWhile p: Returns the longest terminal segment of a list for whichp : α → Boolreturns true.
Implementation detail #
The two predicate-based methods operate by performing the regular "from-left" operation on
List.reverse, followed by another List.reverse, so they are not the most performant.
The other two rely on List.length l so they still traverse the list twice. One could construct
another function that takes a L : ℕ and use L - n. Under a proof condition that
L = l.length, the function would do the right thing.
Drop elements from the tail end of a list that satisfy p : α → Bool.
Implemented naively via List.reverse
Equations
- List.rdropWhile p l = (List.dropWhile p l.reverse).reverse
Instances For
theorem List.rdropWhile_last_not {α : Type u_1} (p : α → Bool) (l : List α) (hl : rdropWhile p l ≠ []) :
Take elements from the tail end of a list that satisfy p : α → Bool.
Implemented naively via List.reverse
Equations
- List.rtakeWhile p l = (List.takeWhile p l.reverse).reverse
Instances For
theorem List.mem_rtakeWhile_imp {α : Type u_1} {p : α → Bool} {l : List α} {x : α} (hx : x ∈ rtakeWhile p l) :
@[simp]