on master help sign in
Reinstate Prelude.Stream.cycle using NonEmpty
653cdefMelvar Chen
libs/prelude/Prelude/Stream.idr+9
@@ -109,6 +109,15 @@ partial -- and the call to foldr isn't guarded anyway!
109scanr : (f : a -> Inf b -> b) -> (xs : Stream a) -> Stream b
109scanr : (f : a -> Inf b -> b) -> (xs : Stream a) -> Stream b
110scanr f (x :: xs) = f x (foldr f xs) :: scanr f xs
110scanr f (x :: xs) = f x (foldr f xs) :: scanr f xs
111
111
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+
112instance Applicative Stream where
121instance Applicative Stream where
113 pure = repeat
122 pure = repeat
114 (<*>) = zipWith apply
123 (<*>) = zipWith apply