generic-labels: Generically extract and replace collections of record fields

[ bsd3, data, generics, library, records ] [ Propose Tags ] [ Report a vulnerability ]

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.

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.1
Change log changelog.md
Dependencies base (>=4.14 && <4.17), generic-lens-core (>=2.0 && <2.2) [details]
License BSD-3-Clause
Author Sam Derbyshire
Maintainer Sam Derbyshire
Revised Revision 1 made by sheaf at 2021-02-09T11:28:09Z
Category Data, Generics, Records
Home page https://github.com/sheaf/generic-labels
Bug tracker https://github.com/sheaf/generic-labels/issues
Source repo head: git clone git://github.com/sheaf/generic-labels
Uploaded by sheaf at 2021-02-09T10:42:17Z
Distributions
Downloads 212 total (2 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2021-02-09 [all 1 reports]