red-black-record-2.1.2.0: Extensible records and variants indexed by a type-level Red-Black tree.

Safe HaskellNone
LanguageHaskell2010

Data.RBR.Subset

Description

This module contains versions of functions from RBR, generalized to work with a subset of the fields of a Record or the branches of a Variant.

Note: There are functions of the same name in the RBR module, but they are deprecated. The functions from this module should be used instead, preferably qualified. The changes have to do mainly with the required constraints.

Synopsis

Documentation

type Subset (subset :: Map Symbol q) (whole :: Map Symbol q) = KeysValuesAll (PresentIn whole) subset Source #

A map is a subset of another if all of its entries are present in the other map.

fieldSubset :: forall subset whole f. (Maplike subset, Subset subset whole) => Record f whole -> (Record f subset -> Record f whole, Record f subset) Source #

Like field, but targets multiple fields at the same time

projectSubset :: forall subset whole f. (Maplike subset, Subset subset whole) => Record f whole -> Record f subset Source #

Like project, but extracts multiple fields at the same time.

The types in the subset tree can often be inferred and left as wildcards in type signature.

>>> prettyShow_RecordI $ S.projectSubset @(Insert "foo" _ (Insert "bar" _ Empty)) (insertI @"foo" 'a' (insertI @"bar" True (insertI @"baz" (Just ()) unit)))
"{bar = True, foo = 'a'}"

Can also be used to convert between Records with structurally dissimilar type-level maps that nevertheless hold the same entries.

getFieldSubset :: forall subset whole f. (Maplike subset, Subset subset whole) => Record f whole -> Record f subset Source #

Alias for projectSubset.

setFieldSubset :: forall subset whole f. (Maplike subset, Subset subset whole) => Record f subset -> Record f whole -> Record f whole Source #

Like setField, but sets multiple fields at the same time.

modifyFieldSubset :: forall subset whole f. (Maplike subset, Subset subset whole) => (Record f subset -> Record f subset) -> Record f whole -> Record f whole Source #

Like modifyField, but modifies multiple fields at the same time.

branchSubset :: forall subset whole f. (Maplike subset, Maplike whole, Subset subset whole) => (Variant f whole -> Maybe (Variant f subset), Variant f subset -> Variant f whole) Source #

Like branch, but targets multiple branches at the same time.

injectSubset :: forall subset whole f. (Maplike subset, Maplike whole, Subset subset whole) => Variant f subset -> Variant f whole Source #

Like inject, but injects one of several possible branches.

Can also be used to convert between Variants with structurally dissimilar type-level maps that nevertheless hold the same entries.

matchSubset :: forall subset whole f. (Maplike subset, Maplike whole, Subset subset whole) => Variant f whole -> Maybe (Variant f subset) Source #

Like match, but matches more than one branch.

fromRecordSuperset :: forall r t whole. (IsRecordType r t, Maplike t, Subset t whole) => Record I whole -> r Source #

A common composition of fromRecord and projectSubset.

eliminateSubset :: forall subset whole f r. (Maplike subset, Maplike whole, Subset subset whole) => Record (Case f r) whole -> Variant f subset -> r Source #

Like eliminate, but allows the eliminator Record to have more fields than there are branches in the Variant.