{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Data.Smash.Lens
(
_Nada
, _Smash
, smashed
, smashing
) where
import Control.Lens
import Data.Smash
smashed :: Traversal (Smash a b) (Smash c d) (a,b) (c,d)
smashed :: ((a, b) -> f (c, d)) -> Smash a b -> f (Smash c d)
smashed (a, b) -> f (c, d)
f = \case
Smash a b
Nada -> Smash c d -> f (Smash c d)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Smash c d
forall a b. Smash a b
Nada
Smash a
a b
b -> (c -> d -> Smash c d) -> (c, d) -> Smash c d
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry c -> d -> Smash c d
forall a b. a -> b -> Smash a b
Smash ((c, d) -> Smash c d) -> f (c, d) -> f (Smash c d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a, b) -> f (c, d)
f (a
a,b
b)
smashing :: Traversal (Smash a a) (Smash b b) a b
smashing :: (a -> f b) -> Smash a a -> f (Smash b b)
smashing = ((a, a) -> f (b, b)) -> Smash a a -> f (Smash b b)
forall a b c d. Traversal (Smash a b) (Smash c d) (a, b) (c, d)
smashed (((a, a) -> f (b, b)) -> Smash a a -> f (Smash b b))
-> ((a -> f b) -> (a, a) -> f (b, b))
-> (a -> f b)
-> Smash a a
-> f (Smash b b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f b) -> (a, a) -> f (b, b)
forall (r :: * -> * -> *) a b.
Bitraversable r =>
Traversal (r a a) (r b b) a b
both
_Nada :: Prism' (Smash a b) ()
_Nada :: p () (f ()) -> p (Smash a b) (f (Smash a b))
_Nada = (() -> Smash a b)
-> (Smash a b -> Either (Smash a b) ())
-> Prism (Smash a b) (Smash a b) () ()
forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism (Smash a b -> () -> Smash a b
forall a b. a -> b -> a
const Smash a b
forall a b. Smash a b
Nada) ((Smash a b -> Either (Smash a b) ())
-> Prism (Smash a b) (Smash a b) () ())
-> (Smash a b -> Either (Smash a b) ())
-> Prism (Smash a b) (Smash a b) () ()
forall a b. (a -> b) -> a -> b
$ \case
Smash a b
Nada -> () -> Either (Smash a b) ()
forall a b. b -> Either a b
Right ()
Smash a
a b
b -> Smash a b -> Either (Smash a b) ()
forall a b. a -> Either a b
Left (a -> b -> Smash a b
forall a b. a -> b -> Smash a b
Smash a
a b
b)
_Smash :: Prism' (Smash a b) (a,b)
_Smash :: p (a, b) (f (a, b)) -> p (Smash a b) (f (Smash a b))
_Smash = ((a, b) -> Smash a b)
-> (Smash a b -> Either (Smash a b) (a, b))
-> Prism (Smash a b) (Smash a b) (a, b) (a, b)
forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism ((a -> b -> Smash a b) -> (a, b) -> Smash a b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> b -> Smash a b
forall a b. a -> b -> Smash a b
Smash) ((Smash a b -> Either (Smash a b) (a, b))
-> Prism (Smash a b) (Smash a b) (a, b) (a, b))
-> (Smash a b -> Either (Smash a b) (a, b))
-> Prism (Smash a b) (Smash a b) (a, b) (a, b)
forall a b. (a -> b) -> a -> b
$ \case
Smash a
a b
b -> (a, b) -> Either (Smash a b) (a, b)
forall a b. b -> Either a b
Right (a
a,b
b)
Smash a b
Nada -> Smash a b -> Either (Smash a b) (a, b)
forall a b. a -> Either a b
Left Smash a b
forall a b. Smash a b
Nada
instance Swapped Smash where
swapped :: p (Smash b a) (f (Smash d c)) -> p (Smash a b) (f (Smash c d))
swapped = (Smash a b -> Smash b a)
-> (Smash d c -> Smash c d)
-> Iso (Smash a b) (Smash c d) (Smash b a) (Smash d c)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Smash a b -> Smash b a
forall a b. Smash a b -> Smash b a
swapSmash Smash d c -> Smash c d
forall a b. Smash a b -> Smash b a
swapSmash
instance (a ~ a', b ~ b') => Each (Smash a a') (Smash b b') a b where
each :: (a -> f b) -> Smash a a' -> f (Smash b b')
each a -> f b
_ Smash a a'
Nada = Smash b b' -> f (Smash b b')
forall (f :: * -> *) a. Applicative f => a -> f a
pure Smash b b'
forall a b. Smash a b
Nada
each a -> f b
f (Smash a
a a'
b) = b -> b -> Smash b b
forall a b. a -> b -> Smash a b
Smash (b -> b -> Smash b b) -> f b -> f (b -> Smash b b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (b -> Smash b b) -> f b -> f (Smash b b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a'
b