Module

Record.Builder

Package
purescript-record
Repository
purescript/purescript-record

#Builder Source

newtype Builder a b

A Builder can be used to build a record by incrementally adding fields in-place, instead of using insert and repeatedly generating new immutable records which need to be garbage collected.

The mutations accumulated in a Builder are safe because intermediate states can't be observed. These mutations, then, are performed all-at-once in the build function.

The Category instance for Builder can be used to compose builders.

For example:

build (insert x 42 >>> insert y "testing") {} :: { x :: Int, y :: String }

Instances

#build Source

build :: forall r2 r1. Builder (Record r1) (Record r2) -> Record r1 -> Record r2

Build a record, starting from some other record.

#insert Source

insert :: forall r2 r1 a l. Cons l a r1 r2 => Lacks l r1 => IsSymbol l => SProxy l -> a -> Builder (Record r1) (Record r2)

Build by inserting a new field.

#modify Source

modify :: forall r2 r1 r b a l. Cons l a r r1 => Cons l b r r2 => IsSymbol l => SProxy l -> (a -> b) -> Builder (Record r1) (Record r2)

Build by modifying an existing field.

#delete Source

delete :: forall r2 r1 a l. IsSymbol l => Lacks l r1 => Cons l a r1 r2 => SProxy l -> Builder (Record r2) (Record r1)

Build by deleting an existing field.

#rename Source

rename :: forall r3 r2 r1 a l2 l1. IsSymbol l1 => IsSymbol l2 => Cons l1 a r2 r1 => Lacks l1 r2 => Cons l2 a r2 r3 => Lacks l2 r2 => SProxy l1 -> SProxy l2 -> Builder (Record r1) (Record r3)

Build by renaming an existing field.

#merge Source

merge :: forall r4 r3 r2 r1. Union r1 r2 r3 => Nub r3 r4 => Record r2 -> Builder (Record r1) (Record r4)

Build by merging existing fields from another record.

#union Source

union :: forall r3 r2 r1. Union r1 r2 r3 => Record r2 -> Builder (Record r1) (Record r3)

Build by merging existing fields from another record. Unlike merge, this does not remove duplicate labels from the resulting record type. This can result in better inference for some pipelines, deferring the need for a Nub constraint.

#disjointUnion Source

disjointUnion :: forall r3 r2 r1. Union r1 r2 r3 => Nub r3 r3 => Record r1 -> Builder (Record r2) (Record r3)

Build by merging some disjoint set of fields from another record.

#nub Source

nub :: forall r2 r1. Nub r1 r2 => Builder (Record r1) (Record r2)

A coercion which removes duplicate labels from a record's type.