generic-labels

Version 0.1.0.1 revision 1 uploaded by sheaf.

Package meta

Synopsis
Generically extract and replace collections of record fields
Description

Handle various conversion operations between record types, such as projecting out a collection of fields from a record, or plugging in values for a subset of the fields of a larger record.

Works both with built-in Haskell records, as well as explicitly labelled types ( #label := value ) :: ( "label" := Type ) .

Project out a smaller record using project:

  data IBXD x = IBXD { i :: Int, b :: Bool, x :: x, d :: Double }
    deriving stock Generic
  data XI x = XI { x :: x, i :: Int }
    deriving stock Generic
  ibxd_to_xi :: IBXD x -> XI x
  ibxd_to_xi = project

Plug in a subset of fields using inject:

  xi_into_ibxd :: XI x -> IBXD x -> IBXD x
  xi_into_ibxd = inject

Create a record out of two collections of arguments using adapt:

  xi_plus_bd_makes_ibxd :: XI x -> ( "b" := Bool, "d" := Double ) -> IBXD x
  xi_plus_bd_makes_ibxd = adapt

See also the library's readme.

Author
Sam Derbyshire
Bug reports
https://github.com/sheaf/generic-labels/issues
Category
Data, Generics, Records
Copyright
n/a
Homepage
https://github.com/sheaf/generic-labels
Maintainer
Sam Derbyshire
Package URL
n/a
Stability
n/a

Components