Is there any replacement for Prelude's iterate function in classy prelude?

157 Views Asked by At

In the standard prelude:

Prelude> :t iterate
iterate :: (a -> a) -> a -> [a]

However, in classy prelude there is no iterate, so I presume there might be some more generic function to do the same, perhaps a monadic one. I just cannot figure out what it is. Is there one?

1

There are 1 best solutions below

1
rampion On

You can always reimplement it with ClassyPrelude.repeat and Data.List.scanl:

iterate = \f a -> scanl (\a f -> f a) a (repeat f)