{-# LANGUAGE CPP #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
#ifdef TRUSTWORTHY
{-# LANGUAGE Trustworthy #-}
#endif
#include "lens-common.h"
module Control.Lens.Each
(
Each(..)
) where
import Prelude ()
import Control.Lens.Traversal
import Control.Lens.Internal.ByteString
import Control.Lens.Internal.Prelude
import Data.Array.Unboxed as Unboxed
import Data.Array.IArray as IArray
import qualified Data.ByteString as StrictB
import qualified Data.ByteString.Lazy as LazyB
import Data.Complex
import Data.HashMap.Lazy (HashMap)
import Data.IntMap (IntMap)
import Data.Map (Map)
import Data.Sequence (Seq)
import Data.Text.Lens (text)
import qualified Data.Text as StrictT
import qualified Data.Text.Lazy as LazyT
import Data.Tree as Tree
import Data.Vector.Generic.Lens (vectorTraverse)
import qualified Data.Vector as Vector
import qualified Data.Vector.Primitive as Prim
import Data.Vector.Primitive (Prim)
import qualified Data.Vector.Storable as Storable
import Data.Vector.Storable (Storable)
import qualified Data.Vector.Unboxed as Unboxed
import Data.Vector.Unboxed (Unbox)
import Data.Word
import qualified Data.Strict as S
import Data.These (These (..))
class Each s t a b | s -> a, t -> b, s b -> t, t a -> s where
each :: Traversal s t a b
default each :: (Traversable g, s ~ g a, t ~ g b) => Traversal s t a b
each = (a -> f b) -> s -> f t
(a -> f b) -> g a -> f (g b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> g a -> f (g b)
traverse
{-# INLINE each #-}
instance (a~a', b~b') => Each (a,a') (b,b') a b where
each :: Traversal (a, a') (b, b') a b
each a -> f b
f ~(a
a,a'
b) = (,) (b -> b' -> (b, b')) -> f b -> f (b' -> (b, b'))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (b' -> (b, b')) -> f b' -> f (b, b')
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a'
b
{-# INLINE each #-}
instance (a~a2, a~a3, b~b2, b~b3) => Each (a,a2,a3) (b,b2,b3) a b where
each :: Traversal (a, a2, a3) (b, b2, b3) a b
each a -> f b
f ~(a
a,a2
b,a3
c) = (,,) (b -> b2 -> b3 -> (b, b2, b3))
-> f b -> f (b2 -> b3 -> (b, b2, b3))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (b2 -> b3 -> (b, b2, b3)) -> f b2 -> f (b3 -> (b, b2, b3))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a2
b f (b3 -> (b, b2, b3)) -> f b3 -> f (b, b2, b3)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a3
c
{-# INLINE each #-}
instance (a~a2, a~a3, a~a4, b~b2, b~b3, b~b4) => Each (a,a2,a3,a4) (b,b2,b3,b4) a b where
each :: Traversal (a, a2, a3, a4) (b, b2, b3, b4) a b
each a -> f b
f ~(a
a,a2
b,a3
c,a4
d) = (,,,) (b -> b2 -> b3 -> b4 -> (b, b2, b3, b4))
-> f b -> f (b2 -> b3 -> b4 -> (b, b2, b3, b4))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (b2 -> b3 -> b4 -> (b, b2, b3, b4))
-> f b2 -> f (b3 -> b4 -> (b, b2, b3, b4))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a2
b f (b3 -> b4 -> (b, b2, b3, b4))
-> f b3 -> f (b4 -> (b, b2, b3, b4))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a3
c f (b4 -> (b, b2, b3, b4)) -> f b4 -> f (b, b2, b3, b4)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a4
d
{-# INLINE each #-}
instance (a~a2, a~a3, a~a4, a~a5, b~b2, b~b3, b~b4, b~b5) => Each (a,a2,a3,a4,a5) (b,b2,b3,b4,b5) a b where
each :: Traversal (a, a2, a3, a4, a5) (b, b2, b3, b4, b5) a b
each a -> f b
f ~(a
a,a2
b,a3
c,a4
d,a5
e) = (,,,,) (b -> b2 -> b3 -> b4 -> b5 -> (b, b2, b3, b4, b5))
-> f b -> f (b2 -> b3 -> b4 -> b5 -> (b, b2, b3, b4, b5))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (b2 -> b3 -> b4 -> b5 -> (b, b2, b3, b4, b5))
-> f b2 -> f (b3 -> b4 -> b5 -> (b, b2, b3, b4, b5))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a2
b f (b3 -> b4 -> b5 -> (b, b2, b3, b4, b5))
-> f b3 -> f (b4 -> b5 -> (b, b2, b3, b4, b5))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a3
c f (b4 -> b5 -> (b, b2, b3, b4, b5))
-> f b4 -> f (b5 -> (b, b2, b3, b4, b5))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a4
d f (b5 -> (b, b2, b3, b4, b5)) -> f b5 -> f (b, b2, b3, b4, b5)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a5
e
{-# INLINE each #-}
instance (a~a2, a~a3, a~a4, a~a5, a~a6, b~b2, b~b3, b~b4, b~b5, b~b6) => Each (a,a2,a3,a4,a5,a6) (b,b2,b3,b4,b5,b6) a b where
each :: Traversal (a, a2, a3, a4, a5, a6) (b, b2, b3, b4, b5, b6) a b
each a -> f b
f ~(a
a,a2
b,a3
c,a4
d,a5
e,a6
g) = (,,,,,) (b -> b2 -> b3 -> b4 -> b5 -> b6 -> (b, b2, b3, b4, b5, b6))
-> f b -> f (b2 -> b3 -> b4 -> b5 -> b6 -> (b, b2, b3, b4, b5, b6))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (b2 -> b3 -> b4 -> b5 -> b6 -> (b, b2, b3, b4, b5, b6))
-> f b2 -> f (b3 -> b4 -> b5 -> b6 -> (b, b2, b3, b4, b5, b6))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a2
b f (b3 -> b4 -> b5 -> b6 -> (b, b2, b3, b4, b5, b6))
-> f b3 -> f (b4 -> b5 -> b6 -> (b, b2, b3, b4, b5, b6))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a3
c f (b4 -> b5 -> b6 -> (b, b2, b3, b4, b5, b6))
-> f b4 -> f (b5 -> b6 -> (b, b2, b3, b4, b5, b6))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a4
d f (b5 -> b6 -> (b, b2, b3, b4, b5, b6))
-> f b5 -> f (b6 -> (b, b2, b3, b4, b5, b6))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a5
e f (b6 -> (b, b2, b3, b4, b5, b6))
-> f b6 -> f (b, b2, b3, b4, b5, b6)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a6
g
{-# INLINE each #-}
instance (a~a2, a~a3, a~a4, a~a5, a~a6, a~a7, b~b2, b~b3, b~b4, b~b5, b~b6, b~b7) => Each (a,a2,a3,a4,a5,a6,a7) (b,b2,b3,b4,b5,b6,b7) a b where
each :: Traversal
(a, a2, a3, a4, a5, a6, a7) (b, b2, b3, b4, b5, b6, b7) a b
each a -> f b
f ~(a
a,a2
b,a3
c,a4
d,a5
e,a6
g,a7
h) = (,,,,,,) (b
-> b2 -> b3 -> b4 -> b5 -> b6 -> b7 -> (b, b2, b3, b4, b5, b6, b7))
-> f b
-> f (b2
-> b3 -> b4 -> b5 -> b6 -> b7 -> (b, b2, b3, b4, b5, b6, b7))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (b2 -> b3 -> b4 -> b5 -> b6 -> b7 -> (b, b2, b3, b4, b5, b6, b7))
-> f b2
-> f (b3 -> b4 -> b5 -> b6 -> b7 -> (b, b2, b3, b4, b5, b6, b7))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a2
b f (b3 -> b4 -> b5 -> b6 -> b7 -> (b, b2, b3, b4, b5, b6, b7))
-> f b3 -> f (b4 -> b5 -> b6 -> b7 -> (b, b2, b3, b4, b5, b6, b7))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a3
c f (b4 -> b5 -> b6 -> b7 -> (b, b2, b3, b4, b5, b6, b7))
-> f b4 -> f (b5 -> b6 -> b7 -> (b, b2, b3, b4, b5, b6, b7))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a4
d f (b5 -> b6 -> b7 -> (b, b2, b3, b4, b5, b6, b7))
-> f b5 -> f (b6 -> b7 -> (b, b2, b3, b4, b5, b6, b7))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a5
e f (b6 -> b7 -> (b, b2, b3, b4, b5, b6, b7))
-> f b6 -> f (b7 -> (b, b2, b3, b4, b5, b6, b7))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a6
g f (b7 -> (b, b2, b3, b4, b5, b6, b7))
-> f b7 -> f (b, b2, b3, b4, b5, b6, b7)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a7
h
{-# INLINE each #-}
instance (a~a2, a~a3, a~a4, a~a5, a~a6, a~a7, a~a8, b~b2, b~b3, b~b4, b~b5, b~b6, b~b7, b~b8) => Each (a,a2,a3,a4,a5,a6,a7,a8) (b,b2,b3,b4,b5,b6,b7,b8) a b where
each :: Traversal
(a, a2, a3, a4, a5, a6, a7, a8) (b, b2, b3, b4, b5, b6, b7, b8) a b
each a -> f b
f ~(a
a,a2
b,a3
c,a4
d,a5
e,a6
g,a7
h,a8
i) = (,,,,,,,) (b
-> b2
-> b3
-> b4
-> b5
-> b6
-> b7
-> b8
-> (b, b2, b3, b4, b5, b6, b7, b8))
-> f b
-> f (b2
-> b3
-> b4
-> b5
-> b6
-> b7
-> b8
-> (b, b2, b3, b4, b5, b6, b7, b8))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (b2
-> b3
-> b4
-> b5
-> b6
-> b7
-> b8
-> (b, b2, b3, b4, b5, b6, b7, b8))
-> f b2
-> f (b3
-> b4 -> b5 -> b6 -> b7 -> b8 -> (b, b2, b3, b4, b5, b6, b7, b8))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a2
b f (b3
-> b4 -> b5 -> b6 -> b7 -> b8 -> (b, b2, b3, b4, b5, b6, b7, b8))
-> f b3
-> f (b4
-> b5 -> b6 -> b7 -> b8 -> (b, b2, b3, b4, b5, b6, b7, b8))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a3
c f (b4 -> b5 -> b6 -> b7 -> b8 -> (b, b2, b3, b4, b5, b6, b7, b8))
-> f b4
-> f (b5 -> b6 -> b7 -> b8 -> (b, b2, b3, b4, b5, b6, b7, b8))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a4
d f (b5 -> b6 -> b7 -> b8 -> (b, b2, b3, b4, b5, b6, b7, b8))
-> f b5 -> f (b6 -> b7 -> b8 -> (b, b2, b3, b4, b5, b6, b7, b8))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a5
e f (b6 -> b7 -> b8 -> (b, b2, b3, b4, b5, b6, b7, b8))
-> f b6 -> f (b7 -> b8 -> (b, b2, b3, b4, b5, b6, b7, b8))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a6
g f (b7 -> b8 -> (b, b2, b3, b4, b5, b6, b7, b8))
-> f b7 -> f (b8 -> (b, b2, b3, b4, b5, b6, b7, b8))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a7
h f (b8 -> (b, b2, b3, b4, b5, b6, b7, b8))
-> f b8 -> f (b, b2, b3, b4, b5, b6, b7, b8)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a8
i
{-# INLINE each #-}
instance (a~a2, a~a3, a~a4, a~a5, a~a6, a~a7, a~a8, a~a9, b~b2, b~b3, b~b4, b~b5, b~b6, b~b7, b~b8, b~b9) => Each (a,a2,a3,a4,a5,a6,a7,a8,a9) (b,b2,b3,b4,b5,b6,b7,b8,b9) a b where
each :: Traversal
(a, a2, a3, a4, a5, a6, a7, a8, a9)
(b, b2, b3, b4, b5, b6, b7, b8, b9)
a
b
each a -> f b
f ~(a
a,a2
b,a3
c,a4
d,a5
e,a6
g,a7
h,a8
i,a9
j) = (,,,,,,,,) (b
-> b2
-> b3
-> b4
-> b5
-> b6
-> b7
-> b8
-> b9
-> (b, b2, b3, b4, b5, b6, b7, b8, b9))
-> f b
-> f (b2
-> b3
-> b4
-> b5
-> b6
-> b7
-> b8
-> b9
-> (b, b2, b3, b4, b5, b6, b7, b8, b9))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (b2
-> b3
-> b4
-> b5
-> b6
-> b7
-> b8
-> b9
-> (b, b2, b3, b4, b5, b6, b7, b8, b9))
-> f b2
-> f (b3
-> b4
-> b5
-> b6
-> b7
-> b8
-> b9
-> (b, b2, b3, b4, b5, b6, b7, b8, b9))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a2
b f (b3
-> b4
-> b5
-> b6
-> b7
-> b8
-> b9
-> (b, b2, b3, b4, b5, b6, b7, b8, b9))
-> f b3
-> f (b4
-> b5
-> b6
-> b7
-> b8
-> b9
-> (b, b2, b3, b4, b5, b6, b7, b8, b9))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a3
c f (b4
-> b5
-> b6
-> b7
-> b8
-> b9
-> (b, b2, b3, b4, b5, b6, b7, b8, b9))
-> f b4
-> f (b5
-> b6 -> b7 -> b8 -> b9 -> (b, b2, b3, b4, b5, b6, b7, b8, b9))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a4
d f (b5
-> b6 -> b7 -> b8 -> b9 -> (b, b2, b3, b4, b5, b6, b7, b8, b9))
-> f b5
-> f (b6 -> b7 -> b8 -> b9 -> (b, b2, b3, b4, b5, b6, b7, b8, b9))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a5
e f (b6 -> b7 -> b8 -> b9 -> (b, b2, b3, b4, b5, b6, b7, b8, b9))
-> f b6
-> f (b7 -> b8 -> b9 -> (b, b2, b3, b4, b5, b6, b7, b8, b9))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a6
g f (b7 -> b8 -> b9 -> (b, b2, b3, b4, b5, b6, b7, b8, b9))
-> f b7 -> f (b8 -> b9 -> (b, b2, b3, b4, b5, b6, b7, b8, b9))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a7
h f (b8 -> b9 -> (b, b2, b3, b4, b5, b6, b7, b8, b9))
-> f b8 -> f (b9 -> (b, b2, b3, b4, b5, b6, b7, b8, b9))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a8
i f (b9 -> (b, b2, b3, b4, b5, b6, b7, b8, b9))
-> f b9 -> f (b, b2, b3, b4, b5, b6, b7, b8, b9)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a9
j
{-# INLINE each #-}
instance Each (Complex a) (Complex b) a b where
each :: Traversal (Complex a) (Complex b) a b
each 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 a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
b
{-# INLINE each #-}
instance (c ~ d) => Each (Map c a) (Map d b) a b where
each :: Traversal (Map c a) (Map d b) a b
each = (a -> f b) -> Map c a -> f (Map c b)
(a -> f b) -> Map c a -> f (Map d b)
forall (f :: * -> *) a b.
Traversable f =>
IndexedTraversal Int (f a) (f b) a b
IndexedTraversal Int (Map c a) (Map c b) a b
traversed
{-# INLINE each #-}
instance Each (IntMap a) (IntMap b) a b where
each :: Traversal (IntMap a) (IntMap b) a b
each = (a -> f b) -> IntMap a -> f (IntMap b)
forall (f :: * -> *) a b.
Traversable f =>
IndexedTraversal Int (f a) (f b) a b
IndexedTraversal Int (IntMap a) (IntMap b) a b
traversed
{-# INLINE each #-}
instance (c ~ d) => Each (HashMap c a) (HashMap d b) a b where
each :: Traversal (HashMap c a) (HashMap d b) a b
each = (a -> f b) -> HashMap c a -> f (HashMap c b)
(a -> f b) -> HashMap c a -> f (HashMap d b)
forall (f :: * -> *) a b.
Traversable f =>
IndexedTraversal Int (f a) (f b) a b
IndexedTraversal Int (HashMap c a) (HashMap c b) a b
traversed
{-# INLINE each #-}
instance Each [a] [b] a b where
each :: Traversal [a] [b] a b
each = (a -> f b) -> [a] -> f [b]
forall (f :: * -> *) a b.
Traversable f =>
IndexedTraversal Int (f a) (f b) a b
IndexedTraversal Int [a] [b] a b
traversed
{-# INLINE each #-}
instance Each (NonEmpty a) (NonEmpty b) a b
instance Each (Identity a) (Identity b) a b
instance Each (Maybe a) (Maybe b) a b
instance (a~a', b~b') => Each (Either a a') (Either b b') a b where
each :: Traversal (Either a a') (Either b b') a b
each a -> f b
f (Left a
a) = b -> Either b b'
forall a b. a -> Either a b
Left (b -> Either b b') -> f b -> f (Either b b')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a
each a -> f b
f (Right a'
a ) = b' -> Either b b'
forall a b. b -> Either a b
Right (b' -> Either b b') -> f b' -> f (Either b b')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a'
a
{-# INLINE each #-}
instance Each (Seq a) (Seq b) a b where
each :: Traversal (Seq a) (Seq b) a b
each = (a -> f b) -> Seq a -> f (Seq b)
forall (f :: * -> *) a b.
Traversable f =>
IndexedTraversal Int (f a) (f b) a b
IndexedTraversal Int (Seq a) (Seq b) a b
traversed
{-# INLINE each #-}
instance Each (Tree a) (Tree b) a b
instance Each (Vector.Vector a) (Vector.Vector b) a b where
each :: Traversal (Vector a) (Vector b) a b
each = (a -> f b) -> Vector a -> f (Vector b)
forall (v :: * -> *) a (w :: * -> *) b.
(Vector v a, Vector w b) =>
IndexedTraversal Int (v a) (w b) a b
IndexedTraversal Int (Vector a) (Vector b) a b
vectorTraverse
{-# INLINE each #-}
instance (Prim a, Prim b) => Each (Prim.Vector a) (Prim.Vector b) a b where
each :: Traversal (Vector a) (Vector b) a b
each = (a -> f b) -> Vector a -> f (Vector b)
forall (v :: * -> *) a (w :: * -> *) b.
(Vector v a, Vector w b) =>
IndexedTraversal Int (v a) (w b) a b
IndexedTraversal Int (Vector a) (Vector b) a b
vectorTraverse
{-# INLINE each #-}
instance (Storable a, Storable b) => Each (Storable.Vector a) (Storable.Vector b) a b where
each :: Traversal (Vector a) (Vector b) a b
each = (a -> f b) -> Vector a -> f (Vector b)
forall (v :: * -> *) a (w :: * -> *) b.
(Vector v a, Vector w b) =>
IndexedTraversal Int (v a) (w b) a b
IndexedTraversal Int (Vector a) (Vector b) a b
vectorTraverse
{-# INLINE each #-}
instance (Unbox a, Unbox b) => Each (Unboxed.Vector a) (Unboxed.Vector b) a b where
each :: Traversal (Vector a) (Vector b) a b
each = (a -> f b) -> Vector a -> f (Vector b)
forall (v :: * -> *) a (w :: * -> *) b.
(Vector v a, Vector w b) =>
IndexedTraversal Int (v a) (w b) a b
IndexedTraversal Int (Vector a) (Vector b) a b
vectorTraverse
{-# INLINE each #-}
instance (a ~ Char, b ~ Char) => Each StrictT.Text StrictT.Text a b where
each :: Traversal Text Text a b
each = (a -> f b) -> Text -> f Text
(Char -> f Char) -> Text -> f Text
forall t. IsText t => IndexedTraversal' Int t Char
IndexedTraversal' Int Text Char
text
{-# INLINE each #-}
instance (a ~ Char, b ~ Char) => Each LazyT.Text LazyT.Text a b where
each :: Traversal Text Text a b
each = (a -> f b) -> Text -> f Text
(Char -> f Char) -> Text -> f Text
forall t. IsText t => IndexedTraversal' Int t Char
IndexedTraversal' Int Text Char
text
{-# INLINE each #-}
instance (a ~ Word8, b ~ Word8) => Each StrictB.ByteString StrictB.ByteString a b where
each :: Traversal ByteString ByteString a b
each = (a -> f b) -> ByteString -> f ByteString
(Word8 -> f Word8) -> ByteString -> f ByteString
IndexedTraversal' Int ByteString Word8
traversedStrictTree
{-# INLINE each #-}
instance (a ~ Word8, b ~ Word8) => Each LazyB.ByteString LazyB.ByteString a b where
each :: Traversal ByteString ByteString a b
each = (a -> f b) -> ByteString -> f ByteString
(Word8 -> f Word8) -> ByteString -> f ByteString
IndexedTraversal' Int64 ByteString Word8
traversedLazy
{-# INLINE each #-}
instance (Ix i, i ~ j) => Each (Array i a) (Array j b) a b where
each :: Traversal (Array i a) (Array j b) a b
each a -> f b
f Array i a
arr = (j, j) -> [(j, b)] -> Array j b
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
(i, i) -> [(i, e)] -> a i e
array (Array j a -> (j, j)
forall i. Ix i => Array i a -> (i, i)
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> (i, i)
bounds Array i a
Array j a
arr) ([(j, b)] -> Array j b) -> f [(j, b)] -> f (Array j b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((j, a) -> f (j, b)) -> [(j, a)] -> f [(j, b)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse (\(j
i,a
a) -> (,) j
i (b -> (j, b)) -> f b -> f (j, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a) (Array j a -> [(j, a)]
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> [(i, e)]
IArray.assocs Array i a
Array j a
arr)
{-# INLINE each #-}
instance (Ix i, IArray UArray a, IArray UArray b, i ~ j) => Each (UArray i a) (UArray j b) a b where
each :: Traversal (UArray i a) (UArray j b) a b
each a -> f b
f UArray i a
arr = (j, j) -> [(j, b)] -> UArray j b
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
(i, i) -> [(i, e)] -> a i e
array (UArray j a -> (j, j)
forall i. Ix i => UArray i a -> (i, i)
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> (i, i)
bounds UArray i a
UArray j a
arr) ([(j, b)] -> UArray j b) -> f [(j, b)] -> f (UArray j b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((j, a) -> f (j, b)) -> [(j, a)] -> f [(j, b)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse (\(j
i,a
a) -> (,) j
i (b -> (j, b)) -> f b -> f (j, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a) (UArray j a -> [(j, a)]
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> [(i, e)]
IArray.assocs UArray i a
UArray j a
arr)
{-# INLINE each #-}
instance (a ~ a', b ~ b') => Each (S.Either a a') (S.Either b b') a b where
each :: Traversal (Either a a') (Either b b') a b
each a -> f b
f (S.Left a
x) = b -> Either b b'
forall a b. a -> Either a b
S.Left (b -> Either b b') -> f b -> f (Either b b')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
x
each a -> f b
f (S.Right a'
x) = b' -> Either b b'
forall a b. b -> Either a b
S.Right (b' -> Either b b') -> f b' -> f (Either b b')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a'
x
{-# INLINE each #-}
instance (a~a', b~b') => Each (S.Pair a a') (S.Pair b b') a b where
each :: Traversal (Pair a a') (Pair b b') a b
each a -> f b
f (a
a S.:!: a'
b) = b -> b' -> Pair b b'
forall a b. a -> b -> Pair a b
(S.:!:) (b -> b' -> Pair b b') -> f b -> f (b' -> Pair b b')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (b' -> Pair b b') -> f b' -> f (Pair b b')
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a'
b
{-# INLINE each #-}
instance Each (S.Maybe a) (S.Maybe b) a b
instance (a ~ a', b ~ b') => Each (S.These a a') (S.These b b') a b where
each :: Traversal (These a a') (These b b') a b
each a -> f b
f (S.This a
a) = b -> These b b'
forall a b. a -> These a b
S.This (b -> These b b') -> f b -> f (These b b')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a
each a -> f b
f (S.That a'
b) = b' -> These b b'
forall a b. b -> These a b
S.That (b' -> These b b') -> f b' -> f (These b b')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a'
b
each a -> f b
f (S.These a
a a'
b) = b -> b' -> These b b'
forall a b. a -> b -> These a b
S.These (b -> b' -> These b b') -> f b -> f (b' -> These b b')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (b' -> These b b') -> f b' -> f (These b b')
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a'
b
instance (a ~ a', b ~ b') => Each (These a a') (These b b') a b where
each :: Traversal (These a a') (These b b') a b
each a -> f b
f (This a
a) = b -> These b b'
forall a b. a -> These a b
This (b -> These b b') -> f b -> f (These b b')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a
each a -> f b
f (That a'
b) = b' -> These b b'
forall a b. b -> These a b
That (b' -> These b b') -> f b' -> f (These b b')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a'
b
each a -> f b
f (These a
a a'
b) = b -> b' -> These b b'
forall a b. a -> b -> These a b
These (b -> b' -> These b b') -> f b -> f (b' -> These b b')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (b' -> These b b') -> f b' -> f (These b b')
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a'
b