iterate f x == [x, f x, f (f x), ...]Note that iterate is lazy, potentially leading to thunk build-up if the consumer doesn't force each iterate. See iterate' for a strict variant of this function.
>>> take 10 $ iterate not True [True,False,True,False... >>> take 10 $ iterate (+3) 42 [42,45,48,51,54,57,60,63...
iterate f x = x :| [f x, f (f x), ..]
iterate f x == [x, f x, f (f x), ...]
iterate f x == [x, f x, f (f x), ...]
iterate f x == [x, f x, f (f x), ...]
>>> R.stdout $ R.take 50 $ R.iterate succ 39 ()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY >>> Q.putStrLn $ Q.take 50 $ Q.iterate succ '\'' ()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY
iterate f x == [x, f x, f (f x), ...]
>>> iterate f x = x `Stream.cons` iterate f xGenerate an infinite stream with x as the first element and each successive element derived by applying the function f on the previous element.
>>> Stream.toList $ Stream.take 5 $ Stream.iterate (+1) 1 [1,2,3,4,5]
iterate f x = [x, f x, f (f x), ..]
iterate f x = [x, f x, f (f x), ... ]With the list ending whenever f (f (... (f (f x)) ...)) < f (... (f (f x)) ...). If this never happens, the list will be infinite. By definition:
iterate f = unfoldr (\x -> Just (x, f x))
>>> iterate f x = x `Stream.cons` iterate f xGenerate an infinite stream with x as the first element and each successive element derived by applying the function f on the previous element.
>>> Stream.fold Fold.toList $ Stream.take 5 $ Stream.iterate (+1) 1 [1,2,3,4,5]