{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Data.Smash.Optics
(
_Nada
, _Smash
, smashed
, smashing
) where
import Optics.Each.Core
import Optics.Iso
import Optics.IxTraversal
import Optics.Prism
import Optics.Traversal
import Data.Smash
smashed :: Traversal (Smash a b) (Smash c d) (a,b) (c,d)
smashed = traversalVL $ \f -> \case
Nada -> pure Nada
Smash a b -> uncurry Smash <$> f (a,b)
smashing :: IxTraversal (Maybe Bool) (Smash a a) (Smash b b) a b
smashing = itraversalVL $ \f -> \case
Nada -> pure Nada
Smash a b -> Smash <$> f (Just True) a <*> f (Just False) b
_Nada :: Prism' (Smash a b) ()
_Nada = prism (const Nada) $ \case
Nada -> Right ()
Smash a b -> Left (Smash a b)
_Smash :: Prism' (Smash a b) (a,b)
_Smash = prism (uncurry Smash) $ \case
Smash a b -> Right (a,b)
Nada -> Left Nada
instance Swapped Smash where
swapped = iso swapSmash swapSmash
instance (a ~ a', b ~ b') => Each (Maybe Bool) (Smash a a') (Smash b b') a b where
each = smashing