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
#buildFromScratch Source
buildFromScratch :: forall r. Builder (Record ()) (Record r) -> Record r
Build a record from scratch.
#merge Source
merge :: forall r1 r2 r3 r4. Union r1 r2 r3 => Nub r3 r4 => Record r1 -> Builder (Record r2) (Record r4)
Build by merging existing fields from another record, taking precedence in the case of overlaps.
For example:
build (merge { x: 1, y: "y" }) { y: 2, z: true }
:: { x :: Int, y :: String, z :: Boolean }
#union Source
union :: forall r1 r2 r3. Union r1 r2 r3 => Record r1 -> Builder (Record r2) (Record r3)
Build by merging existing fields from another record, taking precedence
in the case of overlaps. 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.
For example:
build (union { x: 1, y: "y" }) { y: 2, z: true }
:: { x :: Int, y :: String, y :: Int, z :: Boolean }
- Modules
- Record
- Record.
Builder - Record.
Unsafe. Union