-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocs.test.ts
41 lines (38 loc) · 906 Bytes
/
docs.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { complement, pipe } from "./src/composition.ts";
import { anyjuxt } from "./src/juxt.ts";
import { assertEquals } from "std-assert";
import { equals } from "./src/operator.ts";
import { filter } from "./src/filter.ts";
import { reduce } from "./src/reduce.ts";
import { split } from "./src/string.ts";
Deno.test("check docs example works", async () => {
const histogram = pipe(
split(""),
filter(complement(anyjuxt(equals(" "), equals("'")))),
reduce(
(x, y): Promise<Record<string, number>> =>
Promise.resolve({ ...x, [y]: (x[y] || 0) + 1 }),
() => ({}),
),
);
assertEquals(
await histogram("let's see how many times each letter appears here"),
{
l: 2,
e: 10,
t: 4,
s: 4,
h: 3,
o: 1,
w: 1,
m: 2,
a: 4,
n: 1,
y: 1,
i: 1,
c: 1,
r: 3,
p: 2,
},
);
});