squiggle/packages/website/docs/Api/Dictionary.md

72 lines
923 B
Markdown
Raw Normal View History

2022-06-05 20:59:45 +00:00
---
2022-06-11 00:35:48 +00:00
sidebar_position: 2
2022-06-06 03:02:17 +00:00
title: Dictionary
2022-06-05 20:59:45 +00:00
---
2022-06-11 15:57:02 +00:00
2022-06-11 00:35:48 +00:00
### toList
2022-06-11 15:57:02 +00:00
2022-06-06 05:16:29 +00:00
```
2022-06-11 00:35:48 +00:00
Dict.toList: (dict<'a>) => list<list<string|a>>
2022-06-05 20:59:45 +00:00
```
2022-06-11 00:35:48 +00:00
```js
2022-06-11 15:57:02 +00:00
Dict.toList({ foo: 3, bar: 20 }); // [["foo", 3], ["bar", 20]]
2022-06-06 05:16:29 +00:00
```
2022-06-11 00:35:48 +00:00
### fromList
2022-06-11 15:57:02 +00:00
2022-06-06 05:16:29 +00:00
```
2022-06-11 00:35:48 +00:00
Dict.fromList: (list<list<string|'a>>) => dict<'a>
2022-06-05 20:59:45 +00:00
```
2022-06-11 15:57:02 +00:00
2022-06-11 00:35:48 +00:00
```js
2022-06-11 15:57:02 +00:00
Dict.fromList([
["foo", 3],
["bar", 20],
]); // {foo: 3, bar: 20}
2022-06-06 05:16:29 +00:00
```
### keys
2022-06-11 15:57:02 +00:00
2022-06-06 05:16:29 +00:00
```
Dict.keys: (dict<'a>) => list<string>
2022-06-05 20:59:45 +00:00
```
2022-06-11 15:57:02 +00:00
2022-06-11 00:35:48 +00:00
```js
2022-06-11 15:57:02 +00:00
Dict.keys({ foo: 3, bar: 20 }); // ["foo", "bar"]
2022-06-11 00:35:48 +00:00
```
2022-06-06 05:16:29 +00:00
### values
2022-06-11 15:57:02 +00:00
2022-06-06 05:16:29 +00:00
```
Dict.values: (dict<'a>) => list<'a>
2022-06-05 20:59:45 +00:00
```
2022-06-11 15:57:02 +00:00
2022-06-11 00:35:48 +00:00
```js
2022-06-11 15:57:02 +00:00
Dict.values({ foo: 3, bar: 20 }); // [3, 20]
2022-06-11 00:35:48 +00:00
```
2022-06-06 05:16:29 +00:00
### merge
2022-06-11 15:57:02 +00:00
2022-06-06 05:16:29 +00:00
```
Dict.merge: (dict<'a>, dict<'b>) => dict<'a|b>
2022-06-05 20:59:45 +00:00
```
2022-06-11 00:35:48 +00:00
```js
2022-06-11 15:57:02 +00:00
first = { a: 1, b: 2 };
snd = { b: 3, c: 5 };
Dict.merge(first, snd); // {a: 1, b: 3, c: 5}
2022-06-11 00:35:48 +00:00
```
2022-06-06 05:16:29 +00:00
### mergeMany
2022-06-11 15:57:02 +00:00
2022-06-05 20:59:45 +00:00
```
2022-06-06 05:16:29 +00:00
Dict.mergeMany: (list<dict<'a>>) => dict<'a>
2022-06-11 00:35:48 +00:00
```
```js
2022-06-11 15:57:02 +00:00
first = { a: 1, b: 2 };
snd = { b: 3, c: 5 };
Dict.mergeMany([first, snd]); // {a: 1, b: 3, c: 5}
```