You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,48 @@ Functions for working with records and polymorphic labels
11
11
bower install purescript-record
12
12
```
13
13
14
+
## Examples
15
+
16
+
Given some Symbol ("type level String") Proxy (`SProxy`) and a constrained or concrete record type, you can use this library to generically modify records.
17
+
18
+
```purs
19
+
x_ = SProxy :: SProxy "x"
20
+
21
+
-- we can get a value out of a field
22
+
gotX :: Int
23
+
gotX = Record.get x_ { x: 1 }
24
+
25
+
-- we can insert a value into a record that does not have a field at that label yet
26
+
insertedX :: { x :: Int }
27
+
insertedX = Record.insert x_ 1 {}
28
+
29
+
-- we can delete a field from a record at a specific label
30
+
deletedX :: {}
31
+
deletedX = Record.delete x_ { x: 1 }
32
+
33
+
-- we can set a new value for a field
34
+
setX1 :: { x :: Int }
35
+
setX1 = Record.set x_ 1 { x: 0 }
36
+
37
+
-- we can also modify the type of the field by replacing the contents
See the [tests](./test/Main.purs) for more examples.
51
+
52
+
If you need to combine multiple operations and avoid intermediate values, you might consider using either [Record.Builder](https://pursuit.purescript.org/packages/purescript-record/docs/Record.Builder) or [Record.ST](https://pursuit.purescript.org/packages/purescript-record/docs/Record.ST).
53
+
54
+
You can also find an explanation and example of how to use this library [in this tutorial](https://purescript-simple-json.readthedocs.io/en/latest/inferred-record-types.html) of the Simple-JSON docs.
55
+
14
56
## Documentation
15
57
16
58
Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-record).
0 commit comments