{-# LANGUAGE CPP #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE Safe #-}
module Lens.Micro.Contra
(
Getter,
fromSimpleGetter,
Fold,
fromSimpleFold,
)
where
import Lens.Micro
import Lens.Micro.Extras (view)
import Data.Foldable (traverse_)
import Data.Functor.Contravariant (phantom, Contravariant)
#if __GLASGOW_HASKELL__ < 710
import Control.Applicative
#endif
type Getter s a =
forall f. (Contravariant f, Functor f) => (a -> f a) -> s -> f s
fromSimpleGetter :: SimpleGetter s a -> Getter s a
fromSimpleGetter :: forall s a. SimpleGetter s a -> Getter s a
fromSimpleGetter SimpleGetter s a
g a -> f a
f = forall (f :: * -> *) a b.
(Functor f, Contravariant f) =>
f a -> f b
phantom forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a s. Getting a s a -> s -> a
view SimpleGetter s a
g
{-# INLINE fromSimpleGetter #-}
type Fold s a =
forall f. (Contravariant f, Applicative f) => (a -> f a) -> s -> f s
fromSimpleFold :: SimpleFold s a -> Fold s a
fromSimpleFold :: forall s a. SimpleFold s a -> Fold s a
fromSimpleFold SimpleFold s a
g a -> f a
f = forall (f :: * -> *) a b.
(Functor f, Contravariant f) =>
f a -> f b
phantom forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ a -> f a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a s. Getting (Endo [a]) s a -> s -> [a]
toListOf SimpleFold s a
g
{-# INLINE fromSimpleFold #-}