fields-0.1.0: First-class record field combinators with infix record field syntax.

Data.Record.Field.Combinators

Contents

Description

Field combinators.

Synopsis

Basic combinators.

idL :: a :-> aSource

Identity lens.

(#) :: (Field a, Field b, Dst a ~ Src b) => a -> b -> Src a :-> Dst bSource

Field composition with arguments in OO-like order.

(#$) :: Field a => a -> (Dst a -> b) -> Src a :-> bSource

Compose fields with ordinary functions. As functions are one-way, the resulting field cannot be used to set values.

Combinators for Functors, Applicatives and

(<.#>) :: (Functor f, Field a) => f (Src a) -> a -> f (Dst a)Source

Infix fmap for fields.

Examples:

 persons <.#> firstName
 do (v1, v2) <- takeMVar mv <.#> (field1, field2)
    putStrLn . unlines $ [ "v1: " ++ show v1, "v2: " ++ show v2 ]

(<#>) :: (Applicative f, Field a, Field b, Dst a ~ f (Src b)) => a -> b -> Src a :-> f (Dst b)Source

Applicative functor composition for fields.

 book .# characters <#> lastName

(<##>) :: (Monad m, Field a, Field b, Dst a ~ m (Src b), Dst b ~ m c) => a -> b -> Src a :-> m cSource

Flattening monadic composition for fields.

 person .# superior <##> superior <##> superior <##> superior

Zippy assignment.

(*#) :: Field b => [Src b] -> [b] -> [Dst b]Source

Zippy field reference to be used with (=*).

 [ rec1, rec2 ] *# field =* [ value1, value2 ]

(=*) :: Field a => a -> [Dst a] -> [Src a :-> Src a]Source

Zippy infix assignment to be used with (*#).

Assignment and modification in a State monad.

(<=:) :: (MonadState (Src a) m, Field a) => a -> Dst a -> m ()Source

Infix assignment for the State monad.

 (field1, field2) <=: (value1, value2)

(<=~) :: (MonadState (Src a) m, Field a) => a -> (Dst a -> Dst a) -> m ()Source

Infix modification for the State monad.

 (field1, field2) <=~ (f, g)

Utility combinator for comparisons etc.

onField :: Field a => (Dst a -> Dst a -> t) -> a -> Src a -> Src a -> tSource

Utility combinator in the manner of Data.Function.on.

 sortBy (compare `onField` (lastName,firstName)) persons