data-accessor-0.1.1: Utilities for accessing and manipulating fields of records

Data.Accessor.Basic

Description

This module defines the Accessor type. It should be imported with qualification.

Synopsis

Documentation

data T r a Source

The access functions we propose, look very similar to those needed for List.mapAccumL (but parameter order is swapped) and State monad. They get the new value of the field and the record and return the old value of the field and the record with the updated field.

fromSetGet :: (a -> r -> r) -> (r -> a) -> T r aSource

fromLens :: (r -> (a, a -> r)) -> T r aSource

set :: T r a -> a -> r -> rSource

Set the value of a field.

setMany :: [r -> (a, r)] -> r -> rSource

Set many fields at once.

This function could also be used for initialisation of record, if record value with undefined fields is provided.

Drawback: Since all types in a list must have the same type, you can set only values of the same type.

compose :: [r -> r] -> r -> rSource

This is a general function, but it is especially useful for setting many values of different type at once.

(^=) :: T r a -> a -> r -> rSource

set as infix operator. This lets us write first ^= 2+3 $ second ^= 5+7 $ record.

get :: T r a -> r -> aSource

Get the value of a field.

(^.) :: r -> T r a -> aSource

get as infix operator. This lets us write record^.field^.subfield

modify :: T r a -> (a -> a) -> r -> rSource

Transform the value of a field by a function.

(^:) :: T r a -> (a -> a) -> r -> rSource

modify as infix operator. This lets us write record$%field^:subfield^:(1+) or record$%field^:subfield^:(const 1).

($%) :: a -> (a -> b) -> bSource

Flipped version of '($)'.

(<.) :: T b c -> T a b -> T a cSource

Accessor composition the other direction.

 (<.) = flip (.>)

(.>) :: T a b -> T b c -> T a cSource

Accessor composition: Combine an accessor with an accessor to a sub-field. Speak "stack".