Skip to content

Commit

Permalink
drop, fixes #53
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Aug 29, 2022
1 parent e4c8b77 commit 3a2fc8e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,3 +821,18 @@ export function cycle(coll) {
while (true) yield* coll;
});
}

// private
function iterator(x) {
return x[Symbol.iterator]();
}

export function drop(n, xs) {
return new LazyIterable(function* () {
let iter = iterator(xs);
for (let x = 0; x < n; x++) {
iter.next();
}
yield* iter;
});
}
1 change: 1 addition & 0 deletions resources/clava/core.edn
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
disj_BANG_
dissoc
dissoc_BANG_
drop
empty
es6_iterator
even_QMARK_
Expand Down
6 changes: 6 additions & 0 deletions test/clava/compiler_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,5 +1019,11 @@
(is (= 1 (jsv! '(nth [1 2 3] 0))))
(is (eq :default (jsv! '(nth [1 2 3] 5 :default)))))

(deftest drop-test
(let [dropped (jsv! '(drop 3 (range 6)))]
(is (eq [3 4 5] (vec dropped)))
;; iterating over dropped second time, still works:
(is (eq [3 4 5] (vec dropped)))))

(defn init []
(cljs.test/run-tests 'clava.compiler-test 'clava.jsx-test))

0 comments on commit 3a2fc8e

Please sign in to comment.