module Data.Accessor.Tuple where

import qualified Data.Accessor.Basic as Accessor

{- * Example accessors for the pair type -}

{- | Access to the first value of a pair. -}
first :: Accessor.T (a,b) a
first :: T (a, b) a
first = (a -> (a, b) -> (a, b)) -> ((a, b) -> a) -> T (a, b) a
forall a r. (a -> r -> r) -> (r -> a) -> T r a
Accessor.fromSetGet (\x :: a
x (_,y :: b
y) -> (a
x,b
y)) (a, b) -> a
forall a b. (a, b) -> a
fst

{- | Access to the second value of a pair. -}
second :: Accessor.T (a,b) b
second :: T (a, b) b
second = (b -> (a, b) -> (a, b)) -> ((a, b) -> b) -> T (a, b) b
forall a r. (a -> r -> r) -> (r -> a) -> T r a
Accessor.fromSetGet (\y :: b
y (x :: a
x,_) -> (a
x,b
y)) (a, b) -> b
forall a b. (a, b) -> b
snd


{- | Access to the first value of a triple. -}
first3 :: Accessor.T (a,b,c) a
first3 :: T (a, b, c) a
first3 = ((a, b, c) -> (a, a -> (a, b, c))) -> T (a, b, c) a
forall r a. (r -> (a, a -> r)) -> T r a
Accessor.fromLens (((a, b, c) -> (a, a -> (a, b, c))) -> T (a, b, c) a)
-> ((a, b, c) -> (a, a -> (a, b, c))) -> T (a, b, c) a
forall a b. (a -> b) -> a -> b
$ \(xOld :: a
xOld,y :: b
y,z :: c
z) -> (a
xOld, \xNew :: a
xNew -> (a
xNew,b
y,c
z))

{- | Access to the second value of a triple. -}
second3 :: Accessor.T (a,b,c) b
second3 :: T (a, b, c) b
second3 = ((a, b, c) -> (b, b -> (a, b, c))) -> T (a, b, c) b
forall r a. (r -> (a, a -> r)) -> T r a
Accessor.fromLens (((a, b, c) -> (b, b -> (a, b, c))) -> T (a, b, c) b)
-> ((a, b, c) -> (b, b -> (a, b, c))) -> T (a, b, c) b
forall a b. (a -> b) -> a -> b
$ \(x :: a
x,yOld :: b
yOld,z :: c
z) -> (b
yOld, \yNew :: b
yNew -> (a
x,b
yNew,c
z))

{- | Access to the third value of a triple. -}
third3 :: Accessor.T (a,b,c) c
third3 :: T (a, b, c) c
third3 = ((a, b, c) -> (c, c -> (a, b, c))) -> T (a, b, c) c
forall r a. (r -> (a, a -> r)) -> T r a
Accessor.fromLens (((a, b, c) -> (c, c -> (a, b, c))) -> T (a, b, c) c)
-> ((a, b, c) -> (c, c -> (a, b, c))) -> T (a, b, c) c
forall a b. (a -> b) -> a -> b
$ \(x :: a
x,y :: b
y,zOld :: c
zOld) -> (c
zOld, \zNew :: c
zNew -> (a
x,b
y,c
zNew))