0 | module Data.Functor.TraverseSt
2 | import Control.Monad.State
5 | import Data.List.Lazy
21 | interface Functor f => TraversableSt f where
22 | traverseSt : s -> (s -> a -> (s, b)) -> f a -> f b
28 | public export %inline
29 | withIndex : TraversableSt f => f a -> f (Nat, a)
30 | withIndex = traverseSt Z $
\n, x => (S n, n, x)
32 | public export %inline
33 | (.withIndex) : TraversableSt f => f a -> f (Nat, a)
34 | (.withIndex) = withIndex
41 | TraversableSt Stream where
42 | traverseSt s f (x::xs) = do
44 | y :: traverseSt s' f xs
47 | TraversableSt Colist where
48 | traverseSt _ _ [] = []
49 | traverseSt s f (x::xs) = do
51 | y :: traverseSt s' f xs
54 | TraversableSt LazyList where
55 | traverseSt _ _ [] = []
56 | traverseSt s f (x::xs) = do
58 | y :: traverseSt s' f xs
61 | Traversable f => TraversableSt f where
62 | traverseSt s f = evalState s . traverse (ST . pure .: flip f)