-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfp_test.ts
30 lines (27 loc) · 843 Bytes
/
fp_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
import { assertArrayIncludes, assertEquals } from "./test_deps.ts";
import { c, p } from "https://deno.land/x/[email protected]/mod.ts";
import * as mod from "./mod.ts";
import * as fp from "./fp.ts";
Deno.test("All functions are available in functional programming version", () => {
assertArrayIncludes(["curried", ...Object.keys(fp)], Object.keys(mod));
});
Deno.test("With copb", () => {
const pipeline = c(
p(fp.map<number>((x) => x * 100)) // Only needed type annotation, the rest is inferred.
(fp.map(Math.floor))(fp.filter((x) => x % 3 === 0))(fp.reduce(
(str, x) => str + x,
"",
))(Number),
);
assertEquals(
pipeline([
0.4961166694959176,
0.21540769751705935,
0.7146328682274266,
0.5392881687008804,
0.746080578311838,
0.6354297379184395,
]),
2163,
);
});