on master help sign in
Add more Stream functions
commit614c8c5108870f0592a7ee5b4e278faf2a0e807d authorMax New <maxsnew@gmail.com> dateSat 7 Dec 2013, 14:30 (13 years ago) parentc2a6b0d
1 file changed+16−4
libraries/Lazy.elm+16−4
libraries/Lazy.elm+16−4
@@ -35,16 +35,28 @@ cycle x xs = let cycle' ys = case ys of
3535 (y :: ys) -> S { hd = y, tl = thunk (\() -> cycle' ys) }
3636 in cycle' []
3737
38+map : (a -> b) -> Stream a -> Stream b
39+map f xs = S { hd = f (hd xs)
40+ , tl = thunk (\() -> map f (tl xs))
41+ }
42+
43+zip : Stream a -> Stream b -> Stream (a, b)
44+zip = zipWith (\x y -> (x,y))
45+
3846zipWith : (a -> b -> c) -> Stream a -> Stream b -> Stream c
3947zipWith f xs ys = S { hd = f (hd xs) (hd ys)
4048 , tl = thunk (\() -> zipWith f (tl xs) (tl ys)) }
4149
42−observeWhen : Stream a -> Signal b -> Signal a
43−observeWhen str sig = let tls = foldp (\_ -> tl) str sig in
44− hd <~ tls
45−
4650take : Int -> Stream a -> [a]
4751take n xs = case n of
4852 0 -> []
4953 n -> hd xs :: take (n - 1) (tl xs)
5054
55+iterate : (a -> a) -> a -> Stream a
56+iterate f x = S { hd = x
57+ , tl = thunk (\() -> map f (iterate f x))
58+ }
59+
60+observeWhen : Stream a -> Signal b -> Signal a
61+observeWhen str sig = let tls = foldp (\_ -> tl) str sig in
62+ hd <~ tls