module Data.Accessor.Basic (
T, fromSetGet, fromLens, fromWrapper,
self, null, result,
set, (^=), compose,
get, (^.),
modify, (^:),
(.>), (<.),
($%),
merge,
) where
import qualified Data.Accessor.Private as A
import Data.Accessor.Private (T(..), )
import Prelude hiding (null)
fromSetGet :: (a -> r -> r) -> (r -> a) -> T r a
fromSetGet :: forall a r. (a -> r -> r) -> (r -> a) -> T r a
fromSetGet a -> r -> r
setF r -> a
getF =
forall r a. (r -> (a, a -> r)) -> T r a
Cons forall a b. (a -> b) -> a -> b
$ \r
r -> (r -> a
getF r
r, forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> r -> r
setF r
r)
fromLens :: (r -> (a, a -> r)) -> T r a
fromLens :: forall r a. (r -> (a, a -> r)) -> T r a
fromLens = forall r a. (r -> (a, a -> r)) -> T r a
Cons
fromWrapper :: (b -> a) -> (a -> b) -> T a b
fromWrapper :: forall b a. (b -> a) -> (a -> b) -> T a b
fromWrapper b -> a
wrap a -> b
unwrap =
forall a r. (a -> r -> r) -> (r -> a) -> T r a
fromSetGet (forall a b. a -> b -> a
const forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> a
wrap) a -> b
unwrap
self :: T r r
self :: forall r. T r r
self = forall r. T r r
A.self
null :: T r ()
null :: forall r. T r ()
null = forall a r. (a -> r -> r) -> (r -> a) -> T r a
fromSetGet (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a b. a -> b -> a
const) (forall a b. a -> b -> a
const ())
result :: Eq a => a -> T (a -> b) b
result :: forall a b. Eq a => a -> T (a -> b) b
result a
ai =
forall a r. (a -> r -> r) -> (r -> a) -> T r a
fromSetGet (\b
r a -> b
f a
a -> if a
aforall a. Eq a => a -> a -> Bool
==a
ai then b
r else a -> b
f a
a) (forall a b. (a -> b) -> a -> b
$ a
ai)
set :: T r a -> a -> r -> r
set :: forall r a. T r a -> a -> r -> r
set T r a
f a
a r
r = forall a b. (a, b) -> b
snd (forall r a. T r a -> r -> (a, a -> r)
decons T r a
f r
r) a
a
infixr 5 ^=, ^:
(^=) :: T r a -> a -> (r -> r)
^= :: forall r a. T r a -> a -> r -> r
(^=) = forall r a. T r a -> a -> r -> r
set
compose :: [r -> r] -> r -> r
compose :: forall r. [r -> r] -> r -> r
compose = forall a b c. (a -> b -> c) -> b -> a -> c
flip (forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. a -> a
id))
get :: T r a -> r -> a
get :: forall r a. T r a -> r -> a
get T r a
f = forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r a. T r a -> r -> (a, a -> r)
decons T r a
f
infixl 8 ^.
(^.) :: r -> T r a -> a
^. :: forall r a. r -> T r a -> a
(^.) = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall r a. T r a -> r -> a
get
modify :: T r a -> (a -> a) -> (r -> r)
modify :: forall r a. T r a -> (a -> a) -> r -> r
modify T r a
f a -> a
g r
rOld =
let (a
a,a -> r
rSetA) = forall r a. T r a -> r -> (a, a -> r)
decons T r a
f r
rOld
in a -> r
rSetA (a -> a
g a
a)
(^:) :: T r a -> (a -> a) -> (r -> r)
^: :: forall r a. T r a -> (a -> a) -> r -> r
(^:) = forall r a. T r a -> (a -> a) -> r -> r
modify
infixl 0 $%
($%) :: a -> (a -> b) -> b
$% :: forall a b. a -> (a -> b) -> b
($%) = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a b. (a -> b) -> a -> b
($)
infixl 9 .>
(.>) :: T a b -> T b c -> T a c
.> :: forall a b c. T a b -> T b c -> T a c
(.>) = forall a b c. T a b -> T b c -> T a c
A.compose
infixr 9 <.
(<.) :: T b c -> T a b -> T a c
<. :: forall b c a. T b c -> T a b -> T a c
(<.) = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a b c. T a b -> T b c -> T a c
A.compose
merge :: T a b -> T a c -> T a (b,c)
merge :: forall a b c. T a b -> T a c -> T a (b, c)
merge T a b
accB T a c
accC =
forall a r. (a -> r -> r) -> (r -> a) -> T r a
fromSetGet
(\(b
b,c
c) -> forall r a. T r a -> a -> r -> r
set T a b
accB b
b forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r a. T r a -> a -> r -> r
set T a c
accC c
c)
(\a
a -> (forall r a. T r a -> r -> a
get T a b
accB a
a, forall r a. T r a -> r -> a
get T a c
accC a
a))