2020-12-07 19:45:21 +03:00
|
|
|
{
|
2022-02-23 13:32:10 +03:00
|
|
|
record = {
|
2021-08-26 14:59:03 +03:00
|
|
|
map : forall a b. (Str -> a -> b) -> {_: a} -> {_: b}
|
2022-02-23 15:11:55 +03:00
|
|
|
| doc m%"
|
2021-08-26 14:59:03 +03:00
|
|
|
Maps a function on every field of a record. The string argument of the function argument is the name of the
|
|
|
|
field.
|
2020-12-07 19:45:21 +03:00
|
|
|
|
2021-08-26 14:59:03 +03:00
|
|
|
For example:
|
|
|
|
```nickel
|
|
|
|
map (fun s x => s) { hi = 2 } =>
|
|
|
|
{ hi = "hi" }
|
|
|
|
map (fun s x => x + 1) { hello = 1, world = 2 } =>
|
|
|
|
{ hello = 2, world = 3 }
|
|
|
|
```
|
2022-02-23 15:11:55 +03:00
|
|
|
"%m
|
2021-12-29 00:40:49 +03:00
|
|
|
= fun f r => %record_map% r f,
|
2021-03-11 13:39:23 +03:00
|
|
|
|
2022-01-21 21:36:42 +03:00
|
|
|
fields | { ; Dyn} -> List Str
|
2022-02-23 15:11:55 +03:00
|
|
|
| doc m%"
|
2021-08-26 14:59:03 +03:00
|
|
|
Given a record, results in a list of the string representation of all fields in the record.
|
2020-12-07 19:45:21 +03:00
|
|
|
|
2021-08-26 14:59:03 +03:00
|
|
|
```nickel
|
2021-12-29 00:40:49 +03:00
|
|
|
fields { one = 1, two = 2 } =>
|
2021-08-26 14:59:03 +03:00
|
|
|
[ "one", "two" ]
|
|
|
|
```
|
2022-02-23 15:11:55 +03:00
|
|
|
"%m
|
2021-12-29 00:40:49 +03:00
|
|
|
= fun r => %fields% r,
|
2021-08-26 14:59:03 +03:00
|
|
|
|
2022-01-21 21:36:42 +03:00
|
|
|
values | { ; Dyn} -> List
|
2022-02-23 15:11:55 +03:00
|
|
|
| doc m%"
|
2021-08-26 14:59:03 +03:00
|
|
|
Given a record, results in a list containing all the values in that record.
|
|
|
|
|
|
|
|
```nickel
|
2021-12-29 00:40:49 +03:00
|
|
|
values { one = 1, world = "world" }
|
2021-08-26 14:59:03 +03:00
|
|
|
[ 1, "world" ]
|
|
|
|
```
|
2022-02-23 15:11:55 +03:00
|
|
|
"%m
|
2021-12-29 00:40:49 +03:00
|
|
|
= fun r => %values% r,
|
2021-08-26 14:59:03 +03:00
|
|
|
|
2021-12-29 00:40:49 +03:00
|
|
|
has_field : Str -> Dyn -> Bool
|
2022-02-23 15:11:55 +03:00
|
|
|
| doc m%"
|
2021-08-26 14:59:03 +03:00
|
|
|
Given the name of a field and a record, checks if the record contains the given field.
|
|
|
|
|
|
|
|
```nickel
|
2021-12-29 00:40:49 +03:00
|
|
|
has_field "hello" { one = 1, two = 2 } =>
|
2021-08-26 14:59:03 +03:00
|
|
|
false
|
2021-12-29 00:40:49 +03:00
|
|
|
has_field "one" { one = 1, two = 2 } =>
|
2021-08-26 14:59:03 +03:00
|
|
|
true
|
2022-02-23 15:11:55 +03:00
|
|
|
"%m
|
2021-12-29 00:40:49 +03:00
|
|
|
= fun field r => %has_field% field r,
|
2020-12-07 19:45:21 +03:00
|
|
|
}
|
|
|
|
}
|