diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2025-11-09 21:08:12 -0800 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2025-11-09 21:08:30 -0800 |
| commit | 413eaa284e164143c5416cdce5a1de0f9f992409 (patch) | |
| tree | d999e8cbaddefcce9df3265c594083177427b6cb /examples/mapReduce.ts | |
| parent | 93992029bd349185d15de02e0f633e95c62695a9 (diff) | |
map + reduce
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); |
