Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

belt-docs: fix all failing examples #48

Merged
merged 2 commits into from Oct 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 20 additions & 21 deletions pages/belt_docs/hash-set.mdx
Expand Up @@ -40,128 +40,127 @@ The invariant must be held: for two elements who are equal, their hashed value s

Here the compiler would infer `s0` and `s1` having different type so that it would not mix.

```re example
```re sig
let s0: t(int, I0.identity);

let s1: t(int, I1.identity);
```

We can add elements to the collection (see last two lines in the example above). Since this is an mutable data structure, `s1` will contain two pairs.

## t

```
```re sig
type t('a, 'id);
```

## id

```
```re sig
type id('a, 'id) = BeltId.hashable('a, 'id);
```

## make

```
```re sig
let make: (~hintSize: int, ~id: id('a, 'id)) => t('a, 'id);
```

## clear

```
```re sig
let clear: t('a, 'id) => unit;
```

## isEmpty

```
```re sig
let isEmpty: t('a, 'b) => bool;
```

## add

```
```re sig
let add: (t('a, 'id), 'a) => unit;
```

## copy

```
```re sig
let copy: t('a, 'id) => t('a, 'id);
```

## has

```
```re sig
let has: (t('a, 'id), 'a) => bool;
```

## remove

```
```re sig
let remove: (t('a, 'id), 'a) => unit;
```

## forEachU

```
```re sig
let forEachU: (t('a, 'id), [@bs] ('a => unit)) => unit;
```

## forEach

```
```re sig
let forEach: (t('a, 'id), 'a => unit) => unit;
```

Order unspecified.

## reduceU

```
```re sig
let reduceU: (t('a, 'id), 'c, [@bs] (('c, 'a) => 'c)) => 'c;
```

## reduce

```
```re sig
let reduce: (t('a, 'id), 'c, ('c, 'a) => 'c) => 'c;
```

Order unspecified.

## size

```
```re sig
let size: t('a, 'id) => int;
```

## logStats

```
```re sig
let logStats: t('a, 'b) => unit;
```

## toArray

```
```re sig
let toArray: t('a, 'id) => array('a);
```

## fromArray

```
```re sig
let fromArray: (array('a), ~id: id('a, 'id)) => t('a, 'id);
```

## mergeMany

```
```re sig
let mergeMany: (t('a, 'id), array('a)) => unit;
```

## getBucketHistogram

```
```re sig
let getBucketHistogram: t('a, 'b) => array(int);
```
10 changes: 8 additions & 2 deletions pages/belt_docs/map-dict.mdx
Expand Up @@ -85,9 +85,15 @@ let findFirstBy: (t('k, 'v, 'id), ('k, 'v) => bool) => option(('k, 'v));
`findFirstBy(m, p)` uses function `f` to find the first key value pair to match predicate `p`.

```re example
let s0 = fromArray(~id=(module IntCmp), [|(4, "4"), (1, "1"), (2, "2,"(3, ""))|]);
module IntCmp =
Belt.Id.MakeComparable({
type t = int;
let cmp = Pervasives.compare;
});

findFirstBy(s0, (k, v) => k == 4) == option((4, "4"));
let s0 = Belt.Map.Dict.fromArray([|(4, "4"), (1, "1"), (2, "2"), (3, "3")|], ~cmp=IntCmp.cmp);

Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4"));
```

## forEachU
Expand Down
4 changes: 2 additions & 2 deletions pages/belt_docs/map-int.mdx
Expand Up @@ -83,9 +83,9 @@ let findFirstBy: (t('v), (key, 'v) => bool) => option((key, 'v));
`findFirstBy(m, p)` uses function `f` to find the first key value pair to match predicate `p`.

```re example
let s0 = fromArray(~id=(module IntCmp), [|(4, "4"), (1, "1"), (2, "2,"(3, ""))|]);
let s0 = Belt.Map.Int.fromArray([|(4, "4"), (1, "1"), (2, "2"), (3, "3")|]);

findFirstBy(s0, (k, v) => k == 4) == option((4, "4"));
Belt.Map.Int.findFirstBy(s0, (k, v) => k == 4) == Some((4, "4"));
```

## forEachU
Expand Down
4 changes: 2 additions & 2 deletions pages/belt_docs/map-string.mdx
Expand Up @@ -83,9 +83,9 @@ let findFirstBy: (t('v), (key, 'v) => bool) => option((key, 'v));
`findFirstBy(m, p)` uses function `f` to find the first key value pair to match predicate `p`.

```re example
let s0 = fromArray(~id=(module IntCmp), [|(4, "4"), (1, "1"), (2, "2,"(3, ""))|]);
let s0 = Belt.Map.String.fromArray([|("4", 4), ("1", 1), ("2", 2), ("3", 3)|]);

findFirstBy(s0, (k, v) => k == 4) == option((4, "4"));
Belt.Map.String.findFirstBy(s0, (k, _) => k == "4") == Some(("4", 4));
```

## forEachU
Expand Down