diff options
Diffstat (limited to 'examples/mapReduce.ts')
| -rw-r--r-- | examples/mapReduce.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/examples/mapReduce.ts b/examples/mapReduce.ts new file mode 100644 index 0000000..3904b2a --- /dev/null +++ b/examples/mapReduce.ts @@ -0,0 +1,21 @@ +/* +You can do anything with map + reduce! +*/ + +import { createFn } from "../src"; + +const concatNumbers = createFn<[number[]]>()( + `fn(a, reduce(map(a, fn(n, tostring(n))), fn(acc, cur, add(acc,cur)), ""))` +); + +// const result: "1235" +const concatted = concatNumbers([1, 2, 35]); +console.log(concatted); + +const arrayLength = createFn<[any[]]>()( + `fn(a, reduce(a, fn(acc, add(acc, 1)), 0))` +); + +// const length: 2 +const length = arrayLength(["hello", "world"]); +console.log(length); |
