Skip to content

Commit

Permalink
[feat #50] - mapcat (#94)
Browse files Browse the repository at this point in the history
Fixes #50
  • Loading branch information
prabhjots committed Aug 19, 2022
1 parent 28a3194 commit b6de31d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions resources/clava/core.edn
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
filter
first
get
identity
inc
list
list_QMARK_
map
mapcat
map_indexed
mapv
nil_QMARK_
Expand Down
7 changes: 7 additions & 0 deletions test/clava/compiler_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit b6de31d

Please sign in to comment.