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

58 lines
882 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 00:35:48 +00:00
### toList
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
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-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 00:35:48 +00:00
```js
Dict.fromList([["foo", 3], ["bar", 20]]) // {foo: 3, bar: 20}
2022-06-06 05:16:29 +00:00
```
### keys
```
Dict.keys: (dict<'a>) => list<string>
2022-06-05 20:59:45 +00:00
```
2022-06-11 00:35:48 +00:00
```js
Dict.keys({foo: 3, bar: 20}) // ["foo", "bar"]
```
2022-06-06 05:16:29 +00:00
### values
```
Dict.values: (dict<'a>) => list<'a>
2022-06-05 20:59:45 +00:00
```
2022-06-11 00:35:48 +00:00
```js
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
```
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
first = {a: 1, b: 2}
snd = {b: 3, c: 5}
Dict.merge(first, snd) // {a: 1, b: 3, c: 5}
```
2022-06-06 05:16:29 +00:00
### mergeMany
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
first = {a: 1, b: 2}
snd = {b: 3, c: 5}
Dict.mergeMany([first, snd]) // {a: 1, b: 3, c: 5}
2022-06-06 05:16:29 +00:00
```