{-# LANGUAGE Trustworthy #-}
module Lens.Micro.Extras
(
view,
preview,
)
where
import Lens.Micro
import Lens.Micro.Internal
import Control.Applicative
import Data.Monoid
view :: Getting a s a -> s -> a
view :: Getting a s a -> s -> a
view Getting a s a
l = Const a s -> a
forall a k (b :: k). Const a b -> a
getConst (Const a s -> a) -> (s -> Const a s) -> s -> a
forall c b a. Coercible c b => (b -> c) -> (a -> b) -> a -> c
#. Getting a s a
l a -> Const a a
forall k a (b :: k). a -> Const a b
Const
{-# INLINE view #-}
preview :: Getting (First a) s a -> s -> Maybe a
preview :: Getting (First a) s a -> s -> Maybe a
preview Getting (First a) s a
l = First a -> Maybe a
forall a. First a -> Maybe a
getFirst (First a -> Maybe a) -> (s -> First a) -> s -> Maybe a
forall c b a. Coercible c b => (b -> c) -> (a -> b) -> a -> c
#. Getting (First a) s a -> (a -> First a) -> s -> First a
forall r s a. Getting r s a -> (a -> r) -> s -> r
foldMapOf Getting (First a) s a
l (Maybe a -> First a
forall a. Maybe a -> First a
First (Maybe a -> First a) -> (a -> Maybe a) -> a -> First a
forall c b a. Coercible c b => (b -> c) -> (a -> b) -> a -> c
#. a -> Maybe a
forall a. a -> Maybe a
Just)
{-# INLINE preview #-}