on master help sign in
Reinstate Prelude.Stream.cycle using NonEmpty
commit653cdefd5f9a91db80edbc0c12c831696026f19b authorMelvar Chen <Melvar.Chen@googlemail.com> dateTue 22 Sep 2015, 18:51 (11 years ago) parentd03c71c
1 file changed+9
libs/prelude/Prelude/Stream.idr+9
libs/prelude/Prelude/Stream.idr+9
@@ -109,6 +109,15 @@ partial -- and the call to foldr isn't guarded anyway!
109109scanr : (f : a -> Inf b -> b) -> (xs : Stream a) -> Stream b
110110scanr f (x :: xs) = f x (foldr f xs) :: scanr f xs
111111
112+||| Produce a Stream repeating a sequence
113+||| @ xs the sequence to repeat
114+||| @ ok proof that the list is non-empty
115+cycle : (xs : List a) -> {auto ok : NonEmpty xs} -> Stream a
116+cycle {a} (x :: xs) {ok = IsNonEmpty} = x :: cycle' xs
117+ where cycle' : List a -> Stream a
118+ cycle' [] = x :: cycle' xs
119+ cycle' (y :: ys) = y :: cycle' ys
120+
112121instance Applicative Stream where
113122 pure = repeat
114123 (<*>) = zipWith apply