From 413eaa284e164143c5416cdce5a1de0f9f992409 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Sun, 9 Nov 2025 21:08:12 -0800 Subject: map + reduce --- examples/mapReduce.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 examples/mapReduce.ts (limited to 'examples/mapReduce.ts') 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); -- cgit v1.2.3-70-g09d2