{-# LANGUAGE CPP, TypeOperators #-}

#if __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE Trustworthy #-}
#endif
-----------------------------------------------------------------------------
-- |
-- 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 Control.Applicative.Backwards
import Control.Applicative.Lift
import Control.Monad.Trans.Identity
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.Functor.Identity
import Data.Functor.Product as Functor
import Data.Functor.Reverse
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
#if __GLASGOW_HASKELL__ < 710
import Data.Traversable
#endif
import Data.Traversable.Instances ()

#if MIN_VERSION_base(4,4,0)
import Data.Complex
#endif

#ifdef MIN_VERSION_containers
import Data.Tree
#endif

#ifdef MIN_VERSION_generic_deriving
import Generics.Deriving.Base
#else
import GHC.Generics
#endif

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  = t (f b) (f d) -> f (t b d)
forall (t :: * -> * -> *) (f :: * -> *) a b.
(Bitraversable1 t, Apply f) =>
t (f a) (f b) -> f (t a b)
bisequence1 (t (f b) (f d) -> f (t b d))
-> (t a c -> t (f b) (f d)) -> t a c -> f (t b d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f b) -> (c -> f d) -> t a c -> t (f b) (f d)
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 = (f a -> f a) -> (f b -> f b) -> t (f a) (f b) -> f (t a 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 f a -> f a
forall a. a -> a
id f b -> f b
forall a. a -> a
id
  {-# INLINE bisequence1 #-}

#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 708
  {-# MINIMAL bitraverse1 | bisequence1 #-}
#endif

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

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

instance Bitraversable1 (,) where
  bitraverse1 :: (a -> f b) -> (c -> f d) -> (a, c) -> f (b, d)
bitraverse1 a -> f b
f c -> f d
g (a
a, c
b) = (,) (b -> d -> (b, d)) -> f b -> f (d -> (b, d))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (d -> (b, d)) -> f d -> f (b, d)
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 :: (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 (b -> d -> (x, b, d)) -> f b -> f (d -> (x, b, d))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (d -> (x, b, d)) -> f d -> f (x, b, d)
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 :: (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 (b -> d -> (x, y, b, d)) -> f b -> f (d -> (x, y, b, d))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (d -> (x, y, b, d)) -> f d -> f (x, y, b, d)
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 :: (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 (b -> d -> (x, y, z, b, d)) -> f b -> f (d -> (x, y, z, b, d))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (d -> (x, y, z, b, d)) -> f d -> f (x, y, z, b, d)
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 :: (a -> f b) -> (c -> f d) -> Const a c -> f (Const b d)
bitraverse1 a -> f b
f c -> f d
_ (Const a
a) = b -> Const b d
forall k a (b :: k). a -> Const a b
Const (b -> Const b d) -> f b -> f (Const b d)
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 :: (a -> f b) -> (c -> f d) -> Tagged a c -> f (Tagged b d)
bitraverse1 a -> f b
_ c -> f d
g (Tagged c
b) = d -> Tagged b d
forall k (s :: k) b. b -> Tagged s b
Tagged (d -> Tagged b d) -> f d -> f (Tagged b d)
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 :: (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 = (p (f b) (g d) -> Biff p f g b d)
-> f (p (f b) (g d)) -> f (Biff p f g b d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap p (f b) (g d) -> Biff p f g b d
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 (f (p (f b) (g d)) -> f (Biff p f g b d))
-> (Biff p f g a c -> f (p (f b) (g d)))
-> Biff p f g a c
-> f (Biff p f g b d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (f a -> f (f b))
-> (g c -> f (g d)) -> p (f a) (g c) -> f (p (f b) (g d))
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 (f b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f) ((c -> f d) -> g c -> f (g d)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 c -> f d
g) (p (f a) (g c) -> f (p (f b) (g d)))
-> (Biff p f g a c -> p (f a) (g c))
-> Biff p f g a c
-> f (p (f b) (g d))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Biff p f g a c -> p (f a) (g c)
forall k1 k2 (p :: k1 -> k2 -> *) k3 (f :: k3 -> k1) k4
       (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 :: (a -> f b) -> (c -> f d) -> Clown f a c -> f (Clown f b d)
bitraverse1 a -> f b
f c -> f d
_ = (f b -> Clown f b d) -> f (f b) -> f (Clown f b d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap f b -> Clown f b d
forall k k1 (f :: k -> *) (a :: k) (b :: k1). f a -> Clown f a b
Clown (f (f b) -> f (Clown f b d))
-> (Clown f a c -> f (f b)) -> Clown f a c -> f (Clown f b d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f b) -> f a -> f (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 -> f (f b)) -> (Clown f a c -> f a) -> Clown f a c -> f (f b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Clown f a c -> f a
forall k1 (f :: k1 -> *) (a :: k1) k2 (b :: k2). Clown f a b -> f a
runClown
  {-# INLINE bitraverse1 #-}

instance Bitraversable1 p => Bitraversable1 (Flip p) where
  bitraverse1 :: (a -> f b) -> (c -> f d) -> Flip p a c -> f (Flip p b d)
bitraverse1 a -> f b
f c -> f d
g = (p d b -> Flip p b d) -> f (p d b) -> f (Flip p b d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap p d b -> Flip p b d
forall k k1 (p :: k -> k1 -> *) (a :: k1) (b :: k).
p b a -> Flip p a b
Flip (f (p d b) -> f (Flip p b d))
-> (Flip p a c -> f (p d b)) -> Flip p a c -> f (Flip p b d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> f d) -> (a -> f b) -> p c a -> f (p d 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 c -> f d
g a -> f b
f (p c a -> f (p d b))
-> (Flip p a c -> p c a) -> Flip p a c -> f (p d b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Flip p a c -> p c a
forall k1 k2 (p :: k2 -> k1 -> *) (a :: k1) (b :: k2).
Flip p a b -> p b a
runFlip
  {-# INLINE bitraverse1 #-}

instance Bitraversable1 p => Traversable1 (Join p) where
  traverse1 :: (a -> f b) -> Join p a -> f (Join p b)
traverse1 a -> f b
f (Join p a a
a) = (p b b -> Join p b) -> f (p b b) -> f (Join p b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap p b b -> Join p b
forall k (p :: k -> k -> *) (a :: k). p a a -> Join p a
Join ((a -> f b) -> (a -> f b) -> p a a -> f (p b 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 a -> f b
f p a a
a)
  {-# INLINE traverse1 #-}
  sequence1 :: Join p (f b) -> f (Join p b)
sequence1 (Join p (f b) (f b)
a) = (p b b -> Join p b) -> f (p b b) -> f (Join p b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap p b b -> Join p b
forall k (p :: k -> k -> *) (a :: k). p a a -> Join p a
Join (p (f b) (f b) -> f (p b b)
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 :: (a -> f b) -> (c -> f d) -> Joker g a c -> f (Joker g b d)
bitraverse1 a -> f b
_ c -> f d
g = (g d -> Joker g b d) -> f (g d) -> f (Joker g b d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap g d -> Joker g b d
forall k k1 (g :: k -> *) (a :: k1) (b :: k). g b -> Joker g a b
Joker (f (g d) -> f (Joker g b d))
-> (Joker g a c -> f (g d)) -> Joker g a c -> f (Joker g b d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> f d) -> g c -> f (g d)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 c -> f d
g (g c -> f (g d)) -> (Joker g a c -> g c) -> Joker g a c -> f (g d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Joker g a c -> g c
forall k1 (g :: k1 -> *) k2 (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 :: (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) = f b d -> g b d -> Product f g b d
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 (f b d -> g b d -> Product f g b d)
-> f (f b d) -> f (g b d -> Product f g b d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f b) -> (c -> f d) -> f a c -> f (f b d)
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 f (g b d -> Product f g b d) -> f (g b d) -> f (Product f g b d)
forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> (a -> f b) -> (c -> f d) -> g a c -> f (g b d)
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 :: (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 = (f (p b d) -> Tannen f p b d)
-> f (f (p b d)) -> f (Tannen f p b d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap f (p b d) -> Tannen f p b d
forall k k1 k2 (f :: k -> *) (p :: k1 -> k2 -> k) (a :: k1)
       (b :: k2).
f (p a b) -> Tannen f p a b
Tannen (f (f (p b d)) -> f (Tannen f p b d))
-> (Tannen f p a c -> f (f (p b d)))
-> Tannen f p a c
-> f (Tannen f p b d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (p a c -> f (p b d)) -> f (p a c) -> f (f (p b d))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 ((a -> f b) -> (c -> f d) -> p a c -> f (p b d)
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 (p a c) -> f (f (p b d)))
-> (Tannen f p a c -> f (p a c)) -> Tannen f p a c -> f (f (p b d))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tannen f p a c -> f (p a c)
forall k1 (f :: k1 -> *) k2 k3 (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 :: (a -> f b)
-> (c -> f d)
-> WrappedBifunctor p a c
-> f (WrappedBifunctor p b d)
bitraverse1 a -> f b
f c -> f d
g = (p b d -> WrappedBifunctor p b d)
-> f (p b d) -> f (WrappedBifunctor p b d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap p b d -> WrappedBifunctor p b d
forall k k1 (p :: k -> k1 -> *) (a :: k) (b :: k1).
p a b -> WrappedBifunctor p a b
WrapBifunctor (f (p b d) -> f (WrappedBifunctor p b d))
-> (WrappedBifunctor p a c -> f (p b d))
-> WrappedBifunctor p a c
-> f (WrappedBifunctor p b d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f b) -> (c -> f d) -> p a c -> f (p b d)
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 (p a c -> f (p b d))
-> (WrappedBifunctor p a c -> p a c)
-> WrappedBifunctor p a c
-> f (p b d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedBifunctor p a c -> p 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 = (f b -> f b) -> t (f b) -> f (t b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 f b -> f b
forall a. a -> a
id
  traverse1 a -> f b
f = t (f b) -> f (t b)
forall (t :: * -> *) (f :: * -> *) b.
(Traversable1 t, Apply f) =>
t (f b) -> f (t b)
sequence1 (t (f b) -> f (t b)) -> (t a -> t (f b)) -> t a -> f (t b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f b) -> t a -> t (f b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> f b
f

#if __GLASGOW_HASKELL__ >= 708
  {-# MINIMAL traverse1 | sequence1 #-}
#endif

instance Traversable1 f => Traversable1 (Rec1 f) where
  traverse1 :: (a -> f b) -> Rec1 f a -> f (Rec1 f b)
traverse1 a -> f b
f (Rec1 f a
as) = f b -> Rec1 f b
forall k (f :: k -> *) (p :: k). f p -> Rec1 f p
Rec1 (f b -> Rec1 f b) -> f (f b) -> f (Rec1 f b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f b) -> f a -> f (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 :: (a -> f b) -> M1 i c f a -> f (M1 i c f b)
traverse1 a -> f b
f (M1 f a
as) = f b -> M1 i c f b
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (f b -> M1 i c f b) -> f (f b) -> f (M1 i c f b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f b) -> f a -> f (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 :: (a -> f b) -> Par1 a -> f (Par1 b)
traverse1 a -> f b
f (Par1 a
a) = b -> Par1 b
forall p. p -> Par1 p
Par1 (b -> Par1 b) -> f b -> f (Par1 b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a

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

instance (Traversable1 f, Traversable1 g) => Traversable1 (f :*: g) where
  traverse1 :: (a -> f b) -> (:*:) f g a -> f ((:*:) f g b)
traverse1 a -> f b
f (f a
as :*: g a
bs) = f b -> g b -> (:*:) f g b
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
(:*:) (f b -> g b -> (:*:) f g b) -> f (f b) -> f (g b -> (:*:) f g b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f b) -> f a -> f (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 f (g b -> (:*:) f g b) -> f (g b) -> f ((:*:) f g b)
forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> (a -> f b) -> g a -> f (g 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 :: (a -> f b) -> (:+:) f g a -> f ((:+:) f g b)
traverse1 a -> f b
f (L1 f a
as) = f b -> (:+:) f g b
forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 (f b -> (:+:) f g b) -> f (f b) -> f ((:+:) f g b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f b) -> f a -> f (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) = g b -> (:+:) f g b
forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 (g b -> (:+:) f g b) -> f (g b) -> f ((:+:) f g b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f b) -> g a -> f (g 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 :: (a -> f b) -> (:.:) f g a -> f ((:.:) f g b)
traverse1 a -> f b
f (Comp1 f (g a)
m) = f (g b) -> (:.:) f g b
forall k2 k1 (f :: k2 -> *) (g :: k1 -> k2) (p :: k1).
f (g p) -> (:.:) f g p
Comp1 (f (g b) -> (:.:) f g b) -> f (f (g b)) -> f ((:.:) f g b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (g a -> f (g b)) -> f (g a) -> f (f (g b))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 ((a -> f b) -> g a -> f (g b)
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 :: (a -> f b) -> Identity a -> f (Identity b)
traverse1 a -> f b
f = (b -> Identity b) -> f b -> f (Identity b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Identity b
forall a. a -> Identity a
Identity (f b -> f (Identity b))
-> (Identity a -> f b) -> Identity a -> f (Identity b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
f (a -> f b) -> (Identity a -> a) -> Identity a -> f b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identity a -> a
forall a. Identity a -> a
runIdentity

instance Traversable1 f => Traversable1 (IdentityT f) where
  traverse1 :: (a -> f b) -> IdentityT f a -> f (IdentityT f b)
traverse1 a -> f b
f = (f b -> IdentityT f b) -> f (f b) -> f (IdentityT f b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap f b -> IdentityT f b
forall k (f :: k -> *) (a :: k). f a -> IdentityT f a
IdentityT (f (f b) -> f (IdentityT f b))
-> (IdentityT f a -> f (f b)) -> IdentityT f a -> f (IdentityT f b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f b) -> f a -> f (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 -> f (f b))
-> (IdentityT f a -> f a) -> IdentityT f a -> f (f b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IdentityT f a -> f a
forall k (f :: k -> *) (a :: k). IdentityT f a -> f a
runIdentityT

instance Traversable1 f => Traversable1 (Backwards f) where
  traverse1 :: (a -> f b) -> Backwards f a -> f (Backwards f b)
traverse1 a -> f b
f = (f b -> Backwards f b) -> f (f b) -> f (Backwards f b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap f b -> Backwards f b
forall k (f :: k -> *) (a :: k). f a -> Backwards f a
Backwards (f (f b) -> f (Backwards f b))
-> (Backwards f a -> f (f b)) -> Backwards f a -> f (Backwards f b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f b) -> f a -> f (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 -> f (f b))
-> (Backwards f a -> f a) -> Backwards f a -> f (f b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Backwards f a -> f a
forall k (f :: k -> *) (a :: k). Backwards f a -> f a
forwards

instance (Traversable1 f, Traversable1 g) => Traversable1 (Compose f g) where
  traverse1 :: (a -> f b) -> Compose f g a -> f (Compose f g b)
traverse1 a -> f b
f = (f (g b) -> Compose f g b) -> f (f (g b)) -> f (Compose f g b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap f (g b) -> Compose f g b
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (f (f (g b)) -> f (Compose f g b))
-> (Compose f g a -> f (f (g b)))
-> Compose f g a
-> f (Compose f g b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (g a -> f (g b)) -> f (g a) -> f (f (g b))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 ((a -> f b) -> g a -> f (g b)
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) -> f (f (g b)))
-> (Compose f g a -> f (g a)) -> Compose f g a -> f (f (g b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compose f g a -> f (g a)
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose

instance Traversable1 f => Traversable1 (Lift f) where
  traverse1 :: (a -> f b) -> Lift f a -> f (Lift f b)
traverse1 a -> f b
f (Pure a
x)  = b -> Lift f b
forall (f :: * -> *) a. a -> Lift f a
Pure (b -> Lift f b) -> f b -> f (Lift f b)
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) = f b -> Lift f b
forall (f :: * -> *) a. f a -> Lift f a
Other (f b -> Lift f b) -> f (f b) -> f (Lift f b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f b) -> f a -> f (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 g) => Traversable1 (Functor.Product f g) where
  traverse1 :: (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) = f b -> g b -> Product f g b
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Functor.Pair (f b -> g b -> Product f g b)
-> f (f b) -> f (g b -> Product f g b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f b) -> f a -> f (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 f (g b -> Product f g b) -> f (g b) -> f (Product f g b)
forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> (a -> f b) -> g a -> f (g 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 (Reverse f) where
  traverse1 :: (a -> f b) -> Reverse f a -> f (Reverse f b)
traverse1 a -> f b
f = (f b -> Reverse f b) -> f (f b) -> f (Reverse f b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap f b -> Reverse f b
forall k (f :: k -> *) (a :: k). f a -> Reverse f a
Reverse (f (f b) -> f (Reverse f b))
-> (Reverse f a -> f (f b)) -> Reverse f a -> f (Reverse f b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Backwards f (f b) -> f (f b)
forall k (f :: k -> *) (a :: k). Backwards f a -> f a
forwards (Backwards f (f b) -> f (f b))
-> (Reverse f a -> Backwards f (f b)) -> Reverse f a -> f (f b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Backwards f b) -> f a -> Backwards f (f b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 (f b -> Backwards f b
forall k (f :: k -> *) (a :: k). f a -> Backwards f a
Backwards (f b -> Backwards f b) -> (a -> f b) -> a -> Backwards f b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
f) (f a -> Backwards f (f b))
-> (Reverse f a -> f a) -> Reverse f a -> Backwards f (f b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Reverse f a -> f a
forall k (f :: k -> *) (a :: k). Reverse f a -> f a
getReverse

instance (Traversable1 f, Traversable1 g) => Traversable1 (Functor.Sum f g) where
  traverse1 :: (a -> f b) -> Sum f g a -> f (Sum f g b)
traverse1 a -> f b
f (Functor.InL f a
x) = f b -> Sum f g b
forall k (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
Functor.InL (f b -> Sum f g b) -> f (f b) -> f (Sum f g b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f b) -> f a -> f (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) = g b -> Sum f g b
forall k (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
Functor.InR (g b -> Sum f g b) -> f (g b) -> f (Sum f g b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f b) -> g a -> f (g 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

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

#ifdef MIN_VERSION_tagged
instance Traversable1 (Tagged a) where
  traverse1 :: (a -> f b) -> Tagged a a -> f (Tagged a b)
traverse1 a -> f b
f (Tagged a
a) = b -> Tagged a b
forall k (s :: k) b. b -> Tagged s b
Tagged (b -> Tagged a b) -> f b -> f (Tagged a b)
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 :: (a -> f b) -> Tree a -> f (Tree b)
traverse1 a -> f b
f (Node a
a []) = (b -> [Tree b] -> Tree b
forall a. a -> [Tree a] -> Tree a
`Node`[]) (b -> Tree b) -> f b -> f (Tree b)
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) -> b -> [Tree b] -> Tree b
forall a. a -> [Tree a] -> Tree a
Node b
b (Tree b
yTree b -> [Tree b] -> [Tree b]
forall a. a -> [a] -> [a]
:[Tree b]
ys)) (b -> NonEmpty (Tree b) -> Tree b)
-> f b -> f (NonEmpty (Tree b) -> Tree b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (NonEmpty (Tree b) -> Tree b)
-> f (NonEmpty (Tree b)) -> f (Tree b)
forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> (Tree a -> f (Tree b))
-> NonEmpty (Tree a) -> f (NonEmpty (Tree b))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 ((a -> f b) -> Tree a -> f (Tree b)
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 Tree a -> [Tree a] -> NonEmpty (Tree a)
forall a. a -> [a] -> NonEmpty a
:| [Tree a]
xs)
#endif

instance Traversable1 NonEmpty where
  traverse1 :: (a -> f b) -> NonEmpty a -> f (NonEmpty b)
traverse1 a -> f b
f (a
a :| []) = (b -> [b] -> NonEmpty b
forall a. a -> [a] -> NonEmpty a
:|[]) (b -> NonEmpty b) -> f b -> f (NonEmpty b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a
  traverse1 a -> f b
f (a
a :| (a
b: [a]
bs)) = (\b
a' (b
b':| [b]
bs') -> b
a' b -> [b] -> NonEmpty b
forall a. a -> [a] -> NonEmpty a
:| b
b'b -> [b] -> [b]
forall a. a -> [a] -> [a]
: [b]
bs') (b -> NonEmpty b -> NonEmpty b)
-> f b -> f (NonEmpty b -> NonEmpty b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (NonEmpty b -> NonEmpty b) -> f (NonEmpty b) -> f (NonEmpty b)
forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> (a -> f b) -> NonEmpty a -> f (NonEmpty b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 a -> f b
f (a
b a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| [a]
bs)

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

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

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

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

#if MIN_VERSION_base(4,8,0)
instance Traversable1 f => Traversable1 (Monoid.Alt f) where
  traverse1 :: (a -> f b) -> Alt f a -> f (Alt f b)
traverse1 a -> f b
g (Monoid.Alt f a
m) = f b -> Alt f b
forall k (f :: k -> *) (a :: k). f a -> Alt f a
Monoid.Alt (f b -> Alt f b) -> f (f b) -> f (Alt f b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f b) -> f a -> f (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
#endif

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

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

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

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