{-# LANGUAGE CPP, TypeOperators #-}
{-# LANGUAGE Trustworthy #-}


-----------------------------------------------------------------------------

-- |

-- Copyright   :  (C) 2011-2015 Edward Kmett

-- License     :  BSD-style (see the file LICENSE)

--

-- Maintainer  :  Edward Kmett <ekmett@gmail.com>

-- Stability   :  provisional

-- Portability :  portable

--

----------------------------------------------------------------------------

module Data.Semigroup.Traversable.Class
  ( Bitraversable1(..)
  , Traversable1(..)
  ) where

import Control.Applicative
import Data.Bitraversable
import Data.Bifunctor
import Data.Bifunctor.Biff
import Data.Bifunctor.Clown
import Data.Bifunctor.Flip
import Data.Bifunctor.Joker
import Data.Bifunctor.Join
import Data.Bifunctor.Product as Bifunctor
import Data.Bifunctor.Tannen
import Data.Bifunctor.Wrapped
import Data.Functor.Apply
import Data.Functor.Compose

import Data.Complex
import Data.Functor.Identity
import Data.Functor.Product as Functor
import Data.Functor.Sum as Functor
import Data.List.NonEmpty (NonEmpty(..))
import qualified Data.Monoid as Monoid
import Data.Orphans ()
import Data.Semigroup as Semigroup
import Data.Semigroup.Foldable
import Data.Semigroup.Bifoldable
#ifdef MIN_VERSION_tagged
import Data.Tagged
#endif
import Data.Traversable.Instances ()
import GHC.Generics

#ifdef MIN_VERSION_containers
import Data.Tree
#endif

import Control.Applicative.Backwards
import Control.Applicative.Lift
import Control.Monad.Trans.Identity
import Data.Functor.Reverse

class (Bifoldable1 t, Bitraversable t) => Bitraversable1 t where
  bitraverse1 :: Apply f => (a -> f b) -> (c -> f d) -> t a c -> f (t b d)
  bitraverse1 a -> f b
f c -> f d
g  = forall (t :: * -> * -> *) (f :: * -> *) a b.
(Bitraversable1 t, Apply f) =>
t (f a) (f b) -> f (t a b)
bisequence1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap a -> f b
f c -> f d
g
  {-# INLINE bitraverse1 #-}

  bisequence1 :: Apply f => t (f a) (f b) -> f (t a b)
  bisequence1 = forall (t :: * -> * -> *) (f :: * -> *) a b c d.
(Bitraversable1 t, Apply f) =>
(a -> f b) -> (c -> f d) -> t a c -> f (t b d)
bitraverse1 forall a. a -> a
id forall a. a -> a
id
  {-# INLINE bisequence1 #-}

  {-# MINIMAL bitraverse1 | bisequence1 #-}

instance Bitraversable1 Arg where
  bitraverse1 :: forall (f :: * -> *) a b c d.
Apply f =>
(a -> f b) -> (c -> f d) -> Arg a c -> f (Arg b d)
bitraverse1 a -> f b
f c -> f d
g (Arg a
a c
b) = forall a b. a -> b -> Arg a b
Arg forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> c -> f d
g c
b

instance Bitraversable1 Either where
  bitraverse1 :: forall (f :: * -> *) a b c d.
Apply f =>
(a -> f b) -> (c -> f d) -> Either a c -> f (Either b d)
bitraverse1 a -> f b
f c -> f d
_ (Left a
a) = forall a b. a -> Either a b
Left forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a
  bitraverse1 a -> f b
_ c -> f d
g (Right c
b) = forall a b. b -> Either a b
Right forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> f d
g c
b
  {-# INLINE bitraverse1 #-}

instance Bitraversable1 (,) where
  bitraverse1 :: forall (f :: * -> *) a b c d.
Apply f =>
(a -> f b) -> (c -> f d) -> (a, c) -> f (b, d)
bitraverse1 a -> f b
f c -> f d
g (a
a, c
b) = (,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> c -> f d
g c
b
  {-# INLINE bitraverse1 #-}

instance Bitraversable1 ((,,) x) where
  bitraverse1 :: forall (f :: * -> *) a b c d.
Apply f =>
(a -> f b) -> (c -> f d) -> (x, a, c) -> f (x, b, d)
bitraverse1 a -> f b
f c -> f d
g (x
x, a
a, c
b) = (,,) x
x forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> c -> f d
g c
b
  {-# INLINE bitraverse1 #-}

instance Bitraversable1 ((,,,) x y) where
  bitraverse1 :: forall (f :: * -> *) a b c d.
Apply f =>
(a -> f b) -> (c -> f d) -> (x, y, a, c) -> f (x, y, b, d)
bitraverse1 a -> f b
f c -> f d
g (x
x, y
y, a
a, c
b) = (,,,) x
x y
y forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> c -> f d
g c
b
  {-# INLINE bitraverse1 #-}

instance Bitraversable1 ((,,,,) x y z) where
  bitraverse1 :: forall (f :: * -> *) a b c d.
Apply f =>
(a -> f b) -> (c -> f d) -> (x, y, z, a, c) -> f (x, y, z, b, d)
bitraverse1 a -> f b
f c -> f d
g (x
x, y
y, z
z, a
a, c
b) = (,,,,) x
x y
y z
z forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> c -> f d
g c
b
  {-# INLINE bitraverse1 #-}

instance Bitraversable1 Const where
  bitraverse1 :: forall (f :: * -> *) a b c d.
Apply f =>
(a -> f b) -> (c -> f d) -> Const a c -> f (Const b d)
bitraverse1 a -> f b
f c -> f d
_ (Const a
a) = forall {k} a (b :: k). a -> Const a b
Const forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a
  {-# INLINE bitraverse1 #-}

#ifdef MIN_VERSION_tagged
instance Bitraversable1 Tagged where
  bitraverse1 :: forall (f :: * -> *) a b c d.
Apply f =>
(a -> f b) -> (c -> f d) -> Tagged a c -> f (Tagged b d)
bitraverse1 a -> f b
_ c -> f d
g (Tagged c
b) = forall {k} (s :: k) b. b -> Tagged s b
Tagged forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> f d
g c
b
  {-# INLINE bitraverse1 #-}
#endif

instance (Bitraversable1 p, Traversable1 f, Traversable1 g) => Bitraversable1 (Biff p f g) where
  bitraverse1 :: forall (f :: * -> *) a b c d.
Apply f =>
(a -> f b) -> (c -> f d) -> Biff p f g a c -> f (Biff p f g b d)
bitraverse1 a -> f b
f c -> f d
g = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} {k1} {k2} {k3} (p :: k -> k1 -> *) (f :: k2 -> k)
       (g :: k3 -> k1) (a :: k2) (b :: k3).
p (f a) (g b) -> Biff p f g a b
Biff forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> * -> *) (f :: * -> *) a b c d.
(Bitraversable1 t, Apply f) =>
(a -> f b) -> (c -> f d) -> t a c -> f (t b d)
bitraverse1 (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f) (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 c -> f d
g) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} {k3} {k4} (p :: k1 -> k2 -> *) (f :: k3 -> k1)
       (g :: k4 -> k2) (a :: k3) (b :: k4).
Biff p f g a b -> p (f a) (g b)
runBiff
  {-# INLINE bitraverse1 #-}

instance Traversable1 f => Bitraversable1 (Clown f) where
  bitraverse1 :: forall (f :: * -> *) a b c d.
Apply f =>
(a -> f b) -> (c -> f d) -> Clown f a c -> f (Clown f b d)
bitraverse1 a -> f b
f c -> f d
_ = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} {k1} (f :: k -> *) (a :: k) (b :: k1).
f a -> Clown f a b
Clown forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1 -> *) (a :: k1) (b :: k2).
Clown f a b -> f a
runClown
  {-# INLINE bitraverse1 #-}

instance Bitraversable1 p => Bitraversable1 (Flip p) where
  bitraverse1 :: forall (f :: * -> *) a b c d.
Apply f =>
(a -> f b) -> (c -> f d) -> Flip p a c -> f (Flip p b d)
bitraverse1 a -> f b
f c -> f d
g = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} {k1} (p :: k -> k1 -> *) (a :: k1) (b :: k).
p b a -> Flip p a b
Flip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> * -> *) (f :: * -> *) a b c d.
(Bitraversable1 t, Apply f) =>
(a -> f b) -> (c -> f d) -> t a c -> f (t b d)
bitraverse1 c -> f d
g a -> f b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (p :: k1 -> k2 -> *) (a :: k2) (b :: k1).
Flip p a b -> p b a
runFlip
  {-# INLINE bitraverse1 #-}

instance Bitraversable1 p => Traversable1 (Join p) where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Join p a -> f (Join p b)
traverse1 a -> f b
f (Join p a a
a) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} (p :: k -> k -> *) (a :: k). p a a -> Join p a
Join (forall (t :: * -> * -> *) (f :: * -> *) a b c d.
(Bitraversable1 t, Apply f) =>
(a -> f b) -> (c -> f d) -> t a c -> f (t b d)
bitraverse1 a -> f b
f a -> f b
f p a a
a)
  {-# INLINE traverse1 #-}
  sequence1 :: forall (f :: * -> *) b. Apply f => Join p (f b) -> f (Join p b)
sequence1 (Join p (f b) (f b)
a) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} (p :: k -> k -> *) (a :: k). p a a -> Join p a
Join (forall (t :: * -> * -> *) (f :: * -> *) a b.
(Bitraversable1 t, Apply f) =>
t (f a) (f b) -> f (t a b)
bisequence1 p (f b) (f b)
a)
  {-# INLINE sequence1 #-}

instance Traversable1 g => Bitraversable1 (Joker g) where
  bitraverse1 :: forall (f :: * -> *) a b c d.
Apply f =>
(a -> f b) -> (c -> f d) -> Joker g a c -> f (Joker g b d)
bitraverse1 a -> f b
_ c -> f d
g = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} {k1} (g :: k -> *) (a :: k1) (b :: k).
g b -> Joker g a b
Joker forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 c -> f d
g forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (g :: k1 -> *) (a :: k2) (b :: k1).
Joker g a b -> g b
runJoker
  {-# INLINE bitraverse1 #-}

instance (Bitraversable1 f, Bitraversable1 g) => Bitraversable1 (Bifunctor.Product f g) where
  bitraverse1 :: forall (f :: * -> *) a b c d.
Apply f =>
(a -> f b) -> (c -> f d) -> Product f g a c -> f (Product f g b d)
bitraverse1 a -> f b
f c -> f d
g (Bifunctor.Pair f a c
x g a c
y) = forall {k} {k1} (f :: k -> k1 -> *) (g :: k -> k1 -> *) (a :: k)
       (b :: k1).
f a b -> g a b -> Product f g a b
Bifunctor.Pair forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> * -> *) (f :: * -> *) a b c d.
(Bitraversable1 t, Apply f) =>
(a -> f b) -> (c -> f d) -> t a c -> f (t b d)
bitraverse1 a -> f b
f c -> f d
g f a c
x forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> forall (t :: * -> * -> *) (f :: * -> *) a b c d.
(Bitraversable1 t, Apply f) =>
(a -> f b) -> (c -> f d) -> t a c -> f (t b d)
bitraverse1 a -> f b
f c -> f d
g g a c
y
  {-# INLINE bitraverse1 #-}

instance (Traversable1 f, Bitraversable1 p) => Bitraversable1 (Tannen f p) where
  bitraverse1 :: forall (f :: * -> *) a b c d.
Apply f =>
(a -> f b) -> (c -> f d) -> Tannen f p a c -> f (Tannen f p b d)
bitraverse1 a -> f b
f c -> f d
g = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} {k1} {k2} (f :: k -> *) (p :: k1 -> k2 -> k) (a :: k1)
       (b :: k2).
f (p a b) -> Tannen f p a b
Tannen forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 (forall (t :: * -> * -> *) (f :: * -> *) a b c d.
(Bitraversable1 t, Apply f) =>
(a -> f b) -> (c -> f d) -> t a c -> f (t b d)
bitraverse1 a -> f b
f c -> f d
g) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} {k3} (f :: k1 -> *) (p :: k2 -> k3 -> k1)
       (a :: k2) (b :: k3).
Tannen f p a b -> f (p a b)
runTannen
  {-# INLINE bitraverse1 #-}

instance Bitraversable1 p => Bitraversable1 (WrappedBifunctor p) where
  bitraverse1 :: forall (f :: * -> *) a b c d.
Apply f =>
(a -> f b)
-> (c -> f d)
-> WrappedBifunctor p a c
-> f (WrappedBifunctor p b d)
bitraverse1 a -> f b
f c -> f d
g = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} {k1} (p :: k -> k1 -> *) (a :: k) (b :: k1).
p a b -> WrappedBifunctor p a b
WrapBifunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> * -> *) (f :: * -> *) a b c d.
(Bitraversable1 t, Apply f) =>
(a -> f b) -> (c -> f d) -> t a c -> f (t b d)
bitraverse1 a -> f b
f c -> f d
g forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (p :: k1 -> k2 -> *) (a :: k1) (b :: k2).
WrappedBifunctor p a b -> p a b
unwrapBifunctor
  {-# INLINE bitraverse1 #-}


class (Foldable1 t, Traversable t) => Traversable1 t where
  traverse1 :: Apply f => (a -> f b) -> t a -> f (t b)
  sequence1 :: Apply f => t (f b) -> f (t b)

  sequence1 = forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 forall a. a -> a
id
  traverse1 a -> f b
f = forall (t :: * -> *) (f :: * -> *) b.
(Traversable1 t, Apply f) =>
t (f b) -> f (t b)
sequence1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> f b
f

  {-# MINIMAL traverse1 | sequence1 #-}

instance Traversable1 f => Traversable1 (Rec1 f) where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Rec1 f a -> f (Rec1 f b)
traverse1 a -> f b
f (Rec1 f a
as) = forall k (f :: k -> *) (p :: k). f p -> Rec1 f p
Rec1 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f f a
as

instance Traversable1 f => Traversable1 (M1 i c f) where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> M1 i c f a -> f (M1 i c f b)
traverse1 a -> f b
f (M1 f a
as) = forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f f a
as

instance Traversable1 Par1 where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Par1 a -> f (Par1 b)
traverse1 a -> f b
f (Par1 a
a) = forall p. p -> Par1 p
Par1 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a

instance Traversable1 V1 where
  traverse1 :: forall (f :: * -> *) a b. Apply f => (a -> f b) -> V1 a -> f (V1 b)
traverse1 a -> f b
_ V1 a
v = V1 a
v seq :: forall a b. a -> b -> b
`seq` forall a. HasCallStack => a
undefined

instance (Traversable1 f, Traversable1 g) => Traversable1 (f :*: g) where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> (:*:) f g a -> f ((:*:) f g b)
traverse1 a -> f b
f (f a
as :*: g a
bs) = forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
(:*:) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f f a
as forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f g a
bs

instance (Traversable1 f, Traversable1 g) => Traversable1 (f :+: g) where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> (:+:) f g a -> f ((:+:) f g b)
traverse1 a -> f b
f (L1 f a
as) = forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f f a
as
  traverse1 a -> f b
f (R1 g a
bs) = forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f g a
bs

instance (Traversable1 f, Traversable1 g) => Traversable1 (f :.: g) where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> (:.:) f g a -> f ((:.:) f g b)
traverse1 a -> f b
f (Comp1 f (g a)
m) = forall k2 k1 (f :: k2 -> *) (g :: k1 -> k2) (p :: k1).
f (g p) -> (:.:) f g p
Comp1 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f) f (g a)
m

instance Traversable1 Identity where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Identity a -> f (Identity b)
traverse1 a -> f b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. a -> Identity a
Identity forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Identity a -> a
runIdentity

instance (Traversable1 f, Traversable1 g) => Traversable1 (Functor.Product f g) where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Product f g a -> f (Product f g b)
traverse1 a -> f b
f (Functor.Pair f a
a g a
b) = forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Functor.Pair forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f f a
a forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f g a
b

instance (Traversable1 f, Traversable1 g) => Traversable1 (Functor.Sum f g) where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Sum f g a -> f (Sum f g b)
traverse1 a -> f b
f (Functor.InL f a
x) = forall {k} (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
Functor.InL forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f f a
x
  traverse1 a -> f b
f (Functor.InR g a
y) = forall {k} (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
Functor.InR forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f g a
y

instance (Traversable1 f, Traversable1 g) => Traversable1 (Compose f g) where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Compose f g a -> f (Compose f g b)
traverse1 a -> f b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose

instance Traversable1 f => Traversable1 (IdentityT f) where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> IdentityT f a -> f (IdentityT f b)
traverse1 a -> f b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
IdentityT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
runIdentityT

instance Traversable1 f => Traversable1 (Backwards f) where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Backwards f a -> f (Backwards f b)
traverse1 a -> f b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} (f :: k -> *) (a :: k). f a -> Backwards f a
Backwards forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). Backwards f a -> f a
forwards

instance Traversable1 f => Traversable1 (Lift f) where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Lift f a -> f (Lift f b)
traverse1 a -> f b
f (Pure a
x)  = forall (f :: * -> *) a. a -> Lift f a
Pure forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
x
  traverse1 a -> f b
f (Other f a
y) = forall (f :: * -> *) a. f a -> Lift f a
Other forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f f a
y

instance Traversable1 f => Traversable1 (Reverse f) where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Reverse f a -> f (Reverse f b)
traverse1 a -> f b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} (f :: k -> *) (a :: k). f a -> Reverse f a
Reverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). Backwards f a -> f a
forwards forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 (forall {k} (f :: k -> *) (a :: k). f a -> Backwards f a
Backwards forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). Reverse f a -> f a
getReverse

instance Traversable1 Complex where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Complex a -> f (Complex b)
traverse1 a -> f b
f (a
a :+ a
b) = forall a. a -> a -> Complex a
(:+) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> a -> f b
f a
b
  {-# INLINE traverse1 #-}

#ifdef MIN_VERSION_tagged
instance Traversable1 (Tagged a) where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Tagged a a -> f (Tagged a b)
traverse1 a -> f b
f (Tagged a
a) = forall {k} (s :: k) b. b -> Tagged s b
Tagged forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a
#endif

#ifdef MIN_VERSION_containers
instance Traversable1 Tree where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Tree a -> f (Tree b)
traverse1 a -> f b
f (Node a
a []) = (forall a. a -> [Tree a] -> Tree a
`Node`[]) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a
  traverse1 a -> f b
f (Node a
a (Tree a
x:[Tree a]
xs)) = (\b
b (Tree b
y:|[Tree b]
ys) -> forall a. a -> [Tree a] -> Tree a
Node b
b (Tree b
yforall a. a -> [a] -> [a]
:[Tree b]
ys)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f) (Tree a
x forall a. a -> [a] -> NonEmpty a
:| [Tree a]
xs)
#endif

instance Traversable1 NonEmpty where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> NonEmpty a -> f (NonEmpty b)
traverse1 a -> f b
f (a
a :| [a]
as) = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\a
b a -> f (NonEmpty b)
g a
x -> (\b
a' (b
b':| [b]
bs') -> b
a' forall a. a -> [a] -> NonEmpty a
:| b
b'forall a. a -> [a] -> [a]
: [b]
bs') forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
x forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> a -> f (NonEmpty b)
g a
b) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. a -> [a] -> NonEmpty a
:|[]) forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
f) [a]
as a
a

instance Traversable1 ((,) a) where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> (a, a) -> f (a, b)
traverse1 a -> f b
f (a
a, a
b) = (,) a
a forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
b

instance Traversable1 g => Traversable1 (Joker g a) where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Joker g a a -> f (Joker g a b)
traverse1 a -> f b
g = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} {k1} (g :: k -> *) (a :: k1) (b :: k).
g b -> Joker g a b
Joker forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
g forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (g :: k1 -> *) (a :: k2) (b :: k1).
Joker g a b -> g b
runJoker
  {-# INLINE traverse1 #-}

instance Traversable1 Monoid.Sum where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Sum a -> f (Sum b)
traverse1 a -> f b
g (Monoid.Sum a
a) = forall a. a -> Sum a
Monoid.Sum forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
g a
a

instance Traversable1 Monoid.Product where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Product a -> f (Product b)
traverse1 a -> f b
g (Monoid.Product a
a) = forall a. a -> Product a
Monoid.Product forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
g a
a

instance Traversable1 Monoid.Dual where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Dual a -> f (Dual b)
traverse1 a -> f b
g (Monoid.Dual a
a) = forall a. a -> Dual a
Monoid.Dual forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
g a
a

instance Traversable1 f => Traversable1 (Monoid.Alt f) where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Alt f a -> f (Alt f b)
traverse1 a -> f b
g (Monoid.Alt f a
m) = forall {k} (f :: k -> *) (a :: k). f a -> Alt f a
Monoid.Alt forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
g f a
m

instance Traversable1 Semigroup.First where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> First a -> f (First b)
traverse1 a -> f b
g (Semigroup.First a
a) = forall a. a -> First a
Semigroup.First forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
g a
a

instance Traversable1 Semigroup.Last where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Last a -> f (Last b)
traverse1 a -> f b
g (Semigroup.Last a
a) = forall a. a -> Last a
Semigroup.Last forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
g a
a

instance Traversable1 Semigroup.Min where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Min a -> f (Min b)
traverse1 a -> f b
g (Semigroup.Min a
a) = forall a. a -> Min a
Semigroup.Min forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
g a
a

instance Traversable1 Semigroup.Max where
  traverse1 :: forall (f :: * -> *) a b.
Apply f =>
(a -> f b) -> Max a -> f (Max b)
traverse1 a -> f b
g (Semigroup.Max a
a) = forall a. a -> Max a
Semigroup.Max forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
g a
a