on master help sign in
Merge pull request #379 from maxsnew/lazy
1fbb635Evan Czaplicki
libraries/Lazy/Stream.elm+9−5
@@ -51,18 +51,22 @@ cons' = S . lazy
51-}
51-}
52iterate : (a -> a) -> a -> Stream a
52iterate : (a -> a) -> a -> Stream a
53iterate f x = cons' <| \() ->
53iterate f x = cons' <| \() ->
54− (x, map f (iterate f x))
54+ (x, iterate f (f x))
55
55
56{-| Create an infinite Stream of xs. -}
56{-| Create an infinite Stream of xs. -}
57repeat : a -> Stream a
57repeat : a -> Stream a
58−repeat x = iterate id x
58+repeat x = let go = cons x <| \() -> go
59+ in go
59
60
60{-| Cycle through the elements of the nonempty list (x :: xs) -}
61{-| Cycle through the elements of the nonempty list (x :: xs) -}
61cycle : a -> [a] -> Stream a
62cycle : a -> [a] -> Stream a
62cycle x xs = let cycle' ys = case ys of
63cycle x xs = let cycle' ys = case ys of
64+ [] -> go
63− [] -> cons' <| \() ->
65+ (y :: ys) -> cons y <| \() ->
66+ cycle' ys
67+ go = cons' <| \() ->
64− (x, cycle' xs)
68+ (x, cycle' xs)
65− in cycle' []
69+ in go
66
70
67{-| Apply a function to every element of a Stream. -}
71{-| Apply a function to every element of a Stream. -}
68map : (a -> b) -> Stream a -> Stream b
72map : (a -> b) -> Stream a -> Stream b