Zulip Chat Archive

Stream: Is there code for X?

Topic: list.iterate


Yakov Pechersky (May 13 2021 at 21:28):

Do we have something already that does this?

variables {α : Type*}

def list.iterate (f : α  α) : α    list α
| x 0       := []
| x (n + 1) := x :: list.iterate (f x) n

Alex J. Best (May 13 2021 at 21:46):

There is docs#stream.iterate and docs#stream.approx

Eric Wieser (May 13 2021 at 22:08):

Can this be built from docs#list.scanl and docs#list.repeat?

Eric Wieser (May 13 2021 at 22:10):

(repeat f n).scanl id init seems like it would work


Last updated: Dec 20 2023 at 11:08 UTC