{-# language FlexibleContexts #-}
{-# language FlexibleInstances #-}
{-# language MultiParamTypeClasses #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- |
-- Module       : Data.Tuple.Strict.Lens.Empty
-- Copyright    : (c) 2020 Emily Pillmore
-- License      : BSD-style
--
-- Maintainer   : Emily Pillmore <emilypi@cohomolo.gy>
-- Stability    : Experimental
-- Portability  : portable
--
-- 'Control.Lens.Empty.AsEmpty' instances for 'T2' and 'T3'
--
module Data.Tuple.Strict.Lens.Empty
( AsEmpty(..)
) where


import Control.Lens

import Data.Tuple.Strict


instance (AsEmpty a, AsEmpty b) => AsEmpty (T2 a b) where
  _Empty :: p () (f ()) -> p (T2 a b) (f (T2 a b))
_Empty = (() -> T2 a b) -> (T2 a b -> Maybe ()) -> Prism' (T2 a b) ()
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' (\() -> a -> b -> T2 a b
forall a b. a -> b -> T2 a b
T2 (Tagged () (Identity ()) -> Tagged a (Identity a)
forall a. AsEmpty a => Prism' a ()
_Empty (Tagged () (Identity ()) -> Tagged a (Identity a)) -> () -> a
forall t b. AReview t b -> b -> t
# ()) (Tagged () (Identity ()) -> Tagged b (Identity b)
forall a. AsEmpty a => Prism' a ()
_Empty (Tagged () (Identity ()) -> Tagged b (Identity b)) -> () -> b
forall t b. AReview t b -> b -> t
# ())) ((T2 a b -> Maybe ()) -> Prism' (T2 a b) ())
-> (T2 a b -> Maybe ()) -> Prism' (T2 a b) ()
forall a b. (a -> b) -> a -> b
$ \(T2 a
s b
s') -> case (() -> Either () ()) -> a -> Either () a
forall a. AsEmpty a => Prism' a ()
_Empty () -> Either () ()
forall a b. a -> Either a b
Left a
s of
    Left () -> case (() -> Either () ()) -> b -> Either () b
forall a. AsEmpty a => Prism' a ()
_Empty () -> Either () ()
forall a b. a -> Either a b
Left b
s' of
      Left () -> () -> Maybe ()
forall a. a -> Maybe a
Just ()
      Either () b
_ -> Maybe ()
forall a. Maybe a
Nothing
    Either () a
_ -> Maybe ()
forall a. Maybe a
Nothing
  {-# inline _Empty #-}

instance (AsEmpty a, AsEmpty b, AsEmpty c) => AsEmpty (T3 a b c) where
  _Empty :: p () (f ()) -> p (T3 a b c) (f (T3 a b c))
_Empty = (() -> T3 a b c) -> (T3 a b c -> Maybe ()) -> Prism' (T3 a b c) ()
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' (\() -> a -> b -> c -> T3 a b c
forall a b c. a -> b -> c -> T3 a b c
T3 (Tagged () (Identity ()) -> Tagged a (Identity a)
forall a. AsEmpty a => Prism' a ()
_Empty (Tagged () (Identity ()) -> Tagged a (Identity a)) -> () -> a
forall t b. AReview t b -> b -> t
# ()) (Tagged () (Identity ()) -> Tagged b (Identity b)
forall a. AsEmpty a => Prism' a ()
_Empty (Tagged () (Identity ()) -> Tagged b (Identity b)) -> () -> b
forall t b. AReview t b -> b -> t
# ()) (Tagged () (Identity ()) -> Tagged c (Identity c)
forall a. AsEmpty a => Prism' a ()
_Empty (Tagged () (Identity ()) -> Tagged c (Identity c)) -> () -> c
forall t b. AReview t b -> b -> t
# ())) ((T3 a b c -> Maybe ()) -> Prism' (T3 a b c) ())
-> (T3 a b c -> Maybe ()) -> Prism' (T3 a b c) ()
forall a b. (a -> b) -> a -> b
$ \(T3 a
s b
s' c
s'') -> case (() -> Either () ()) -> a -> Either () a
forall a. AsEmpty a => Prism' a ()
_Empty () -> Either () ()
forall a b. a -> Either a b
Left a
s of
    Left () -> case (() -> Either () ()) -> b -> Either () b
forall a. AsEmpty a => Prism' a ()
_Empty () -> Either () ()
forall a b. a -> Either a b
Left b
s' of
      Left () -> case (() -> Either () ()) -> c -> Either () c
forall a. AsEmpty a => Prism' a ()
_Empty () -> Either () ()
forall a b. a -> Either a b
Left c
s'' of
        Left () -> () -> Maybe ()
forall a. a -> Maybe a
Just ()
        Right c
_ -> Maybe ()
forall a. Maybe a
Nothing
      Right b
_ -> Maybe ()
forall a. Maybe a
Nothing
    Right a
_ -> Maybe ()
forall a. Maybe a
Nothing
  {-# inline _Empty #-}