0 | module Monocle.Getter
2 | import Control.Monad.State
16 | record Getter (s,t,a,b : Type) where
21 | public export %inline
22 | (~>) : Getter s t a b -> Getter a b c d -> Getter s t c d
23 | G f ~> G g = G $
g . f
30 | interface ToGetter (0 o : Type -> Type -> Type -> Type -> Type) where
31 | toGetter : o s t a b -> Getter s t a b
33 | public export %inline
34 | ToGetter Getter where toGetter = id
37 | public export %inline
38 | to : ToGetter o => o s t a b -> s -> a
45 | public export %inline
47 | toFold f = F (. to_ f)
55 | getST : Monad m => ToGetter o => o s t a b -> StateT s m a
56 | getST g = to g <$> get
59 | withST : Monad m => ToGetter o => o s s a a -> (a -> StateT s m t) -> StateT s m t
60 | withST g f = getST g >>= f