{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.Strict.Lens (
_Left, _Right,
_Just, _Nothing,
here, there,
_This, _That, _These,
) where
import Control.Applicative (pure, (<$>))
import Prelude (Int, flip, ($), (.))
import qualified Prelude as L
import Control.Lens (Index, Prism, Prism', Traversal, prism,
prism')
import Data.Strict (Either (..), Maybe (..), Pair (..),
These (..), either, maybe, these)
type instance Index (Pair a b) = Int
_Left :: Prism (Either a c) (Either b c) a b
_Left :: forall a c b. Prism (Either a c) (Either b c) a b
_Left = forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a b. b -> Either a b
L.Right (forall a b. a -> Either a b
L.Left forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. b -> Either a b
Right)
_Right :: Prism (Either c a) (Either c b) a b
_Right :: forall c a b. Prism (Either c a) (Either c b) a b
_Right = forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism forall a b. b -> Either a b
Right forall a b. (a -> b) -> a -> b
$ forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a b. a -> Either a b
L.Left forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> Either a b
Left) forall a b. b -> Either a b
L.Right
_Just :: Prism (Maybe a) (Maybe b) a b
_Just :: forall a b. Prism (Maybe a) (Maybe b) a b
_Just = forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a b. a -> Either a b
L.Left forall a. Maybe a
Nothing) forall a b. b -> Either a b
L.Right
_Nothing :: Prism' (Maybe a) ()
_Nothing :: forall a. Prism' (Maybe a) ()
_Nothing = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' (forall a b. a -> b -> a
L.const forall a. Maybe a
Nothing) forall a b. (a -> b) -> a -> b
$ forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a. a -> Maybe a
L.Just ()) (forall a b. a -> b -> a
L.const forall a. Maybe a
L.Nothing)
here :: Traversal (These a c) (These b c) a b
here :: forall a c b. Traversal (These a c) (These b c) a b
here a -> f b
f (This a
x) = forall a b. a -> These a b
This forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
x
here a -> f b
f (These a
x c
y) = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a b. a -> b -> These a b
These c
y forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
x
here a -> f b
_ (That c
x) = forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a b. b -> These a b
That c
x)
there :: Traversal (These c a) (These c b) a b
there :: forall c a b. Traversal (These c a) (These c b) a b
there a -> f b
_ (This c
x) = forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a b. a -> These a b
This c
x)
there a -> f b
f (These c
x a
y) = forall a b. a -> b -> These a b
These c
x forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
y
there a -> f b
f (That a
x) = forall a b. b -> These a b
That forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
x
_This :: Prism' (These a b) a
_This :: forall a b. Prism' (These a b) a
_This = forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism forall a b. a -> These a b
This (forall a c b.
(a -> c) -> (b -> c) -> (a -> b -> c) -> These a b -> c
these forall a b. b -> Either a b
L.Right (forall a b. a -> Either a b
L.Left forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. b -> These a b
That) (\a
x b
y -> forall a b. a -> Either a b
L.Left forall a b. (a -> b) -> a -> b
$ forall a b. a -> b -> These a b
These a
x b
y))
_That :: Prism' (These a b) b
_That :: forall a b. Prism' (These a b) b
_That = forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism forall a b. b -> These a b
That (forall a c b.
(a -> c) -> (b -> c) -> (a -> b -> c) -> These a b -> c
these (forall a b. a -> Either a b
L.Left forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> These a b
This) forall a b. b -> Either a b
L.Right (\a
x b
y -> forall a b. a -> Either a b
L.Left forall a b. (a -> b) -> a -> b
$ forall a b. a -> b -> These a b
These a
x b
y))
_These :: Prism' (These a b) (a, b)
_These :: forall a b. Prism' (These a b) (a, b)
_These = forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism (\(a
a,b
b) -> forall a b. a -> b -> These a b
These a
a b
b) (forall a c b.
(a -> c) -> (b -> c) -> (a -> b -> c) -> These a b -> c
these (forall a b. a -> Either a b
L.Left forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> These a b
This) (forall a b. a -> Either a b
L.Left forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. b -> These a b
That) (\a
x b
y -> forall a b. b -> Either a b
L.Right (a
x, b
y)))