From 3eedf41c93dc15d73bbda5734a7c7cddb49ce2da Mon Sep 17 00:00:00 2001 From: Prabhjot Singh Date: Sat, 20 Aug 2022 03:58:21 +1000 Subject: [PATCH] [feat #50] - mapcat (#94) Fixes #50 --- core.js | 8 ++++++++ resources/clava/core.edn | 2 ++ test/clava/compiler_test.cljs | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/core.js b/core.js index 0290e6c5..d29ef13b 100644 --- a/core.js +++ b/core.js @@ -549,3 +549,11 @@ export function concat(...colls) { } return ret; } + +export function mapcat(f, ...colls) { + return concat(...map(f, ...colls)); +} + +export function identity(x) { + return x; +} \ No newline at end of file diff --git a/resources/clava/core.edn b/resources/clava/core.edn index c454d1b1..8f80583e 100644 --- a/resources/clava/core.edn +++ b/resources/clava/core.edn @@ -26,10 +26,12 @@ filter first get + identity inc list list_QMARK_ map + mapcat map_indexed mapv nil_QMARK_ diff --git a/test/clava/compiler_test.cljs b/test/clava/compiler_test.cljs index 12fbd548..75b1fab2 100644 --- a/test/clava/compiler_test.cljs +++ b/test/clava/compiler_test.cljs @@ -798,5 +798,12 @@ (is (eq [0 1 2 3 4 5 6 7 8 9] (jsv! '(concat [0 1 2 3] [4 5 6] [7 8 9])))) (is (eq [["a" "b"] ["c" "d"] 2] (jsv! '(concat {"a" "b" "c" "d"} [2]))))) +(deftest mapcat-test + (is (eq [] (jsv! '(mapcat identity nil)))) + (is (eq [0 1 2 3 4 5 6 7 8 9] (jsv! '(mapcat identity [[0 1 2 3] [4 5 6] [7 8 9]])))) + (is (eq ["a" "b" "c" "d"] (jsv! '(mapcat identity {"a" "b" "c" "d"})))) + (testing "multiple colls" + (is (eq ["a" 1 "b" 2] (jsv! '(mapcat list [:a :b :c] [1 2])))))) + (defn init [] (cljs.test/run-tests 'clava.compiler-test))