{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Data.Wedge.Optics
(
here
, there
, _Nowhere
, _Here
, _There
) where
import Data.Wedge
import Optics.Each.Core
import Optics.Iso
import Optics.IxTraversal
import Optics.Prism
import Optics.Traversal
here :: Traversal (Wedge a b) (Wedge a' b) a a'
here = traversalVL $ \f -> \case
Nowhere -> pure Nowhere
Here a -> Here <$> f a
There b -> pure (There b)
there :: Traversal (Wedge a b) (Wedge a b') b b'
there = traversalVL $ \f -> \case
Nowhere -> pure Nowhere
Here a -> pure (Here a)
There b -> There <$> f b
_Nowhere :: Prism' (Wedge a b) ()
_Nowhere = prism (const Nowhere) $ \case
Nowhere -> Right ()
Here a -> Left (Here a)
There b -> Left (There b)
_Here :: Prism (Wedge a b) (Wedge c b) a c
_Here = prism Here $ \case
Here a -> Right a
There b -> Left (There b)
Nowhere -> Left Nowhere
_There :: Prism (Wedge a b) (Wedge a d) b d
_There = prism There $ \case
There b -> Right b
Here a -> Left (Here a)
Nowhere -> Left (Nowhere)
instance Swapped Wedge where
swapped = iso swapWedge swapWedge
instance (a ~ a', b ~ b') => Each (Maybe Bool) (Wedge a a') (Wedge b b') a b where
each = itraversalVL $ \f -> \case
Here a -> Here <$> f (Just True) a
There b -> There <$> f (Just False) b
Nowhere -> pure Nowhere