Drop up to n
values from the stream s
.
Equations
- Stream.drop s 0 = s
- Stream.drop s n.succ = match Stream.next? s with | none => s | some (fst, s) => Stream.drop s n
Instances For
Read up to n
values from the stream s
as a list from first to last.
Equations
- Stream.take s 0 = ([], s)
- Stream.take s n.succ = match Stream.next? s with | none => ([], s) | some (a, s) => match Stream.take s n with | (as, s) => (a :: as, s)
Instances For
Tail recursive version of Stream.take
.
Equations
- Stream.takeTR s n = Stream.takeTR.loop s [] n
Instances For
Inner loop for Stream.takeTR
.
Equations
- Stream.takeTR.loop s acc 0 = (acc.reverse, s)
- Stream.takeTR.loop s acc n.succ = match Stream.next? s with | none => (acc.reverse, s) | some (a, s) => Stream.takeTR.loop s (a :: acc) n
Instances For
theorem
Stream.fst_takeTR_loop
{σ : Type u_1}
{α : Type u_2}
[Stream σ α]
(s : σ)
(acc : List α)
(n : Nat)
:
(takeTR.loop s acc n).fst = acc.reverseAux (take s n).fst
theorem
Stream.snd_takeTR_loop
{σ : Type u_1}
{α : Type u_2}
[Stream σ α]
(s : σ)
(acc : List α)
(n : Nat)
:
(takeTR.loop s acc n).snd = drop s n
@[simp]
@[simp]
theorem
List.stream_take_eq_take_drop
{α : Type u_1}
{n : Nat}
(l : List α)
:
Stream.take l n = (take n l, drop n l)