{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE StrictData #-}

module Data.Tuple.Strict.T3
  ( T3 (..),
  )
where

import Control.DeepSeq (NFData, rnf)
import Data.Biapplicative
import Data.Bifoldable
import Data.Bitraversable
import Data.Hashable (Hashable, hash, hashWithSalt)
import Data.Hashable.Lifted
  ( Hashable1,
    Hashable2,
    defaultLiftHashWithSalt,
    hashWithSalt1,
    liftHashWithSalt,
    liftHashWithSalt2,
  )
import Data.Semigroup
import GHC.Generics (Generic)

data T3 a b c
  = T3 a b c
  deriving stock (T3 a b c
T3 a b c -> T3 a b c -> Bounded (T3 a b c)
forall a. a -> a -> Bounded a
forall a b c. (Bounded a, Bounded b, Bounded c) => T3 a b c
maxBound :: T3 a b c
$cmaxBound :: forall a b c. (Bounded a, Bounded b, Bounded c) => T3 a b c
minBound :: T3 a b c
$cminBound :: forall a b c. (Bounded a, Bounded b, Bounded c) => T3 a b c
Bounded, T3 a b c -> T3 a b c -> Bool
(T3 a b c -> T3 a b c -> Bool)
-> (T3 a b c -> T3 a b c -> Bool) -> Eq (T3 a b c)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b c. (Eq a, Eq b, Eq c) => T3 a b c -> T3 a b c -> Bool
/= :: T3 a b c -> T3 a b c -> Bool
$c/= :: forall a b c. (Eq a, Eq b, Eq c) => T3 a b c -> T3 a b c -> Bool
== :: T3 a b c -> T3 a b c -> Bool
$c== :: forall a b c. (Eq a, Eq b, Eq c) => T3 a b c -> T3 a b c -> Bool
Eq, Eq (T3 a b c)
Eq (T3 a b c)
-> (T3 a b c -> T3 a b c -> Ordering)
-> (T3 a b c -> T3 a b c -> Bool)
-> (T3 a b c -> T3 a b c -> Bool)
-> (T3 a b c -> T3 a b c -> Bool)
-> (T3 a b c -> T3 a b c -> Bool)
-> (T3 a b c -> T3 a b c -> T3 a b c)
-> (T3 a b c -> T3 a b c -> T3 a b c)
-> Ord (T3 a b c)
T3 a b c -> T3 a b c -> Bool
T3 a b c -> T3 a b c -> Ordering
T3 a b c -> T3 a b c -> T3 a b c
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a b c. (Ord a, Ord b, Ord c) => Eq (T3 a b c)
forall a b c. (Ord a, Ord b, Ord c) => T3 a b c -> T3 a b c -> Bool
forall a b c.
(Ord a, Ord b, Ord c) =>
T3 a b c -> T3 a b c -> Ordering
forall a b c.
(Ord a, Ord b, Ord c) =>
T3 a b c -> T3 a b c -> T3 a b c
min :: T3 a b c -> T3 a b c -> T3 a b c
$cmin :: forall a b c.
(Ord a, Ord b, Ord c) =>
T3 a b c -> T3 a b c -> T3 a b c
max :: T3 a b c -> T3 a b c -> T3 a b c
$cmax :: forall a b c.
(Ord a, Ord b, Ord c) =>
T3 a b c -> T3 a b c -> T3 a b c
>= :: T3 a b c -> T3 a b c -> Bool
$c>= :: forall a b c. (Ord a, Ord b, Ord c) => T3 a b c -> T3 a b c -> Bool
> :: T3 a b c -> T3 a b c -> Bool
$c> :: forall a b c. (Ord a, Ord b, Ord c) => T3 a b c -> T3 a b c -> Bool
<= :: T3 a b c -> T3 a b c -> Bool
$c<= :: forall a b c. (Ord a, Ord b, Ord c) => T3 a b c -> T3 a b c -> Bool
< :: T3 a b c -> T3 a b c -> Bool
$c< :: forall a b c. (Ord a, Ord b, Ord c) => T3 a b c -> T3 a b c -> Bool
compare :: T3 a b c -> T3 a b c -> Ordering
$ccompare :: forall a b c.
(Ord a, Ord b, Ord c) =>
T3 a b c -> T3 a b c -> Ordering
$cp1Ord :: forall a b c. (Ord a, Ord b, Ord c) => Eq (T3 a b c)
Ord, ReadPrec [T3 a b c]
ReadPrec (T3 a b c)
Int -> ReadS (T3 a b c)
ReadS [T3 a b c]
(Int -> ReadS (T3 a b c))
-> ReadS [T3 a b c]
-> ReadPrec (T3 a b c)
-> ReadPrec [T3 a b c]
-> Read (T3 a b c)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall a b c. (Read a, Read b, Read c) => ReadPrec [T3 a b c]
forall a b c. (Read a, Read b, Read c) => ReadPrec (T3 a b c)
forall a b c. (Read a, Read b, Read c) => Int -> ReadS (T3 a b c)
forall a b c. (Read a, Read b, Read c) => ReadS [T3 a b c]
readListPrec :: ReadPrec [T3 a b c]
$creadListPrec :: forall a b c. (Read a, Read b, Read c) => ReadPrec [T3 a b c]
readPrec :: ReadPrec (T3 a b c)
$creadPrec :: forall a b c. (Read a, Read b, Read c) => ReadPrec (T3 a b c)
readList :: ReadS [T3 a b c]
$creadList :: forall a b c. (Read a, Read b, Read c) => ReadS [T3 a b c]
readsPrec :: Int -> ReadS (T3 a b c)
$creadsPrec :: forall a b c. (Read a, Read b, Read c) => Int -> ReadS (T3 a b c)
Read, Int -> T3 a b c -> ShowS
[T3 a b c] -> ShowS
T3 a b c -> String
(Int -> T3 a b c -> ShowS)
-> (T3 a b c -> String) -> ([T3 a b c] -> ShowS) -> Show (T3 a b c)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b c. (Show a, Show b, Show c) => Int -> T3 a b c -> ShowS
forall a b c. (Show a, Show b, Show c) => [T3 a b c] -> ShowS
forall a b c. (Show a, Show b, Show c) => T3 a b c -> String
showList :: [T3 a b c] -> ShowS
$cshowList :: forall a b c. (Show a, Show b, Show c) => [T3 a b c] -> ShowS
show :: T3 a b c -> String
$cshow :: forall a b c. (Show a, Show b, Show c) => T3 a b c -> String
showsPrec :: Int -> T3 a b c -> ShowS
$cshowsPrec :: forall a b c. (Show a, Show b, Show c) => Int -> T3 a b c -> ShowS
Show, (forall x. T3 a b c -> Rep (T3 a b c) x)
-> (forall x. Rep (T3 a b c) x -> T3 a b c) -> Generic (T3 a b c)
forall x. Rep (T3 a b c) x -> T3 a b c
forall x. T3 a b c -> Rep (T3 a b c) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b c x. Rep (T3 a b c) x -> T3 a b c
forall a b c x. T3 a b c -> Rep (T3 a b c) x
$cto :: forall a b c x. Rep (T3 a b c) x -> T3 a b c
$cfrom :: forall a b c x. T3 a b c -> Rep (T3 a b c) x
Generic)

-- | @since 0.1.3
deriving stock instance Foldable (T3 a b)

-- | @since 0.1.3
deriving stock instance Functor (T3 a b)

-- | @since 0.1.3
deriving stock instance Traversable (T3 a b)

-- | @since 0.1.3
instance (Monoid a, Monoid b) => Applicative (T3 a b) where
  pure :: a -> T3 a b a
pure a
c = a -> b -> a -> T3 a b a
forall a b c. a -> b -> c -> T3 a b c
T3 a
forall a. Monoid a => a
mempty b
forall a. Monoid a => a
mempty a
c
  T3 a
a b
b a -> b
f <*> :: T3 a b (a -> b) -> T3 a b a -> T3 a b b
<*> T3 a
a' b
b' a
c = a -> b -> b -> T3 a b b
forall a b c. a -> b -> c -> T3 a b c
T3 (a
a a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
a') (b
b b -> b -> b
forall a. Semigroup a => a -> a -> a
<> b
b') (a -> b
f a
c)

-- | @since 0.1.3
instance (Monoid a, Monoid b) => Monad (T3 a b) where
  return :: a -> T3 a b a
return = a -> T3 a b a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
  T3 a
a b
b a
c >>= :: T3 a b a -> (a -> T3 a b b) -> T3 a b b
>>= a -> T3 a b b
f = case a -> T3 a b b
f a
c of
    T3 a
a' b
b' b
c' -> a -> b -> b -> T3 a b b
forall a b c. a -> b -> c -> T3 a b c
T3 (a
a a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
a') (b
b b -> b -> b
forall a. Semigroup a => a -> a -> a
<> b
b') b
c'

instance (Hashable a, Hashable b, Hashable c) => Hashable (T3 a b c) where
  hash :: T3 a b c -> Int
hash (T3 a
a b
b c
c) = a -> Int
forall a. Hashable a => a -> Int
hash a
a Int -> b -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` b
b Int -> c -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` c
c
  hashWithSalt :: Int -> T3 a b c -> Int
hashWithSalt = Int -> T3 a b c -> Int
forall (f :: * -> *) a.
(Hashable1 f, Hashable a) =>
Int -> f a -> Int
hashWithSalt1

instance (Hashable a, Hashable b) => Hashable1 (T3 a b) where
  liftHashWithSalt :: (Int -> a -> Int) -> Int -> T3 a b a -> Int
liftHashWithSalt = (Int -> a -> Int) -> Int -> T3 a b a -> Int
forall (f :: * -> * -> *) a b.
(Hashable2 f, Hashable a) =>
(Int -> b -> Int) -> Int -> f a b -> Int
defaultLiftHashWithSalt

instance Hashable a => Hashable2 (T3 a) where
  liftHashWithSalt2 :: (Int -> a -> Int) -> (Int -> b -> Int) -> Int -> T3 a a b -> Int
liftHashWithSalt2 Int -> a -> Int
h1 Int -> b -> Int
h2 Int
slt (T3 a
a a
b b
c) =
    (Int
slt Int -> a -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` a
a) Int -> a -> Int
`h1` a
b Int -> b -> Int
`h2` b
c

instance (Monoid a, Monoid b, Monoid c) => Monoid (T3 a b c) where
  mempty :: T3 a b c
mempty = a -> b -> c -> T3 a b c
forall a b c. a -> b -> c -> T3 a b c
T3 a
forall a. Monoid a => a
mempty b
forall a. Monoid a => a
mempty c
forall a. Monoid a => a
mempty

-- | @since 0.1.4
instance (NFData a, NFData b, NFData c) => NFData (T3 a b c) where
  rnf :: T3 a b c -> ()
rnf (T3 a
a b
b c
c) = a -> ()
forall a. NFData a => a -> ()
rnf a
a () -> () -> ()
`seq` b -> ()
forall a. NFData a => a -> ()
rnf b
b () -> () -> ()
`seq` c -> ()
forall a. NFData a => a -> ()
rnf c
c

instance (Semigroup a, Semigroup b, Semigroup c) => Semigroup (T3 a b c) where
  T3 a
a1 b
b1 c
c1 <> :: T3 a b c -> T3 a b c -> T3 a b c
<> T3 a
a2 b
b2 c
c2 = a -> b -> c -> T3 a b c
forall a b c. a -> b -> c -> T3 a b c
T3 (a
a1 a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
a2) (b
b1 b -> b -> b
forall a. Semigroup a => a -> a -> a
<> b
b2) (c
c1 c -> c -> c
forall a. Semigroup a => a -> a -> a
<> c
c2)
  stimes :: b -> T3 a b c -> T3 a b c
stimes b
ii (T3 a
a b
b c
c) = a -> b -> c -> T3 a b c
forall a b c. a -> b -> c -> T3 a b c
T3 (b -> a -> a
forall a b. (Semigroup a, Integral b) => b -> a -> a
stimes b
ii a
a) (b -> b -> b
forall a b. (Semigroup a, Integral b) => b -> a -> a
stimes b
ii b
b) (b -> c -> c
forall a b. (Semigroup a, Integral b) => b -> a -> a
stimes b
ii c
c)

-- | @since 0.1.3
instance Bifunctor (T3 x) where
  bimap :: (a -> b) -> (c -> d) -> T3 x a c -> T3 x b d
bimap a -> b
f c -> d
g (T3 x
x a
a c
b) = x -> b -> d -> T3 x b d
forall a b c. a -> b -> c -> T3 a b c
T3 x
x (a -> b
f a
a) (c -> d
g c
b)

-- | @since 0.1.3
instance Bifoldable (T3 x) where
  bifoldMap :: (a -> m) -> (b -> m) -> T3 x a b -> m
bifoldMap a -> m
f b -> m
g (T3 x
_ a
a b
b) = a -> m
f a
a m -> m -> m
forall a. Semigroup a => a -> a -> a
<> b -> m
g b
b

-- | @since 0.1.3
instance Bitraversable (T3 x) where
  bitraverse :: (a -> f c) -> (b -> f d) -> T3 x a b -> f (T3 x c d)
bitraverse a -> f c
f b -> f d
g (T3 x
x a
a b
b) = x -> c -> d -> T3 x c d
forall a b c. a -> b -> c -> T3 a b c
T3 x
x (c -> d -> T3 x c d) -> f c -> f (d -> T3 x c d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f c
f a
a f (d -> T3 x c d) -> f d -> f (T3 x c d)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> b -> f d
g b
b