aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2021-08-29 15:15:35 +0100
committerLouis Pilfold <louis@lpil.uk>2021-08-29 15:15:35 +0100
commitc67d4fa20c0f479238241076a6ac1e458c65f874 (patch)
treef375d0f232e14517e74028aff4862a7be4780944 /src
parentfbd541429ab4c04e680aeaea2e3f1540b44dca59 (diff)
downloadjavascript-c67d4fa20c0f479238241076a6ac1e458c65f874.tar.gz
javascript-c67d4fa20c0f479238241076a6ac1e458c65f874.zip
Array fold
Diffstat (limited to 'src')
-rw-r--r--src/ffi.js4
-rw-r--r--src/gleam/javascript/array.gleam3
2 files changed, 7 insertions, 0 deletions
diff --git a/src/ffi.js b/src/ffi.js
index 06303fc..91a2f73 100644
--- a/src/ffi.js
+++ b/src/ffi.js
@@ -9,3 +9,7 @@ export function map(thing, fn) {
export function length(thing) {
return thing.length;
}
+
+export function reduce(thing, acc, fn) {
+ return thing.reduce(fn, acc);
+}
diff --git a/src/gleam/javascript/array.gleam b/src/gleam/javascript/array.gleam
index 6c4819e..20d12d1 100644
--- a/src/gleam/javascript/array.gleam
+++ b/src/gleam/javascript/array.gleam
@@ -11,3 +11,6 @@ pub external fn length(Array(element)) -> Int =
pub external fn map(Array(a), fn(a) -> b) -> Array(b) =
"../../ffi.js" "map"
+
+pub external fn fold(Array(e), a, fn(a, e) -> a) -> a =
+ "../../ffi.js" "reduce"