diff --git a/.gitignore b/.gitignore index d87fa45..dc7b5ea 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,11 @@ .shadow-cljs .yarn/* /*-init.clj +/.calva +/.clj-kondo /.cpcache /.lein-* +/.lsp /.nrepl-port /.rebel* /checkouts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b6b8970..1dfe0eb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,3 +11,13 @@ statement: the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this code under copyright law. + +## Running tests + +To run the tests, install yarn and execute: + +``` +yarn run test +``` + +This will compile the cljs code and run the tests. diff --git a/src/beicon/v2/core.cljs b/src/beicon/v2/core.cljs index 2c84f4f..9e4b50f 100644 --- a/src/beicon/v2/core.cljs +++ b/src/beicon/v2/core.cljs @@ -222,7 +222,7 @@ }" rx/combineLatest)) (defn combine-latest-all - "Comboines multiple Observables to create an Observable whose values + "Combines multiple Observables to create an Observable whose values are calculated from the latest values of each of its input Observables (constructor). @@ -489,6 +489,12 @@ ([f seed ob] (ops/pipe (ops/reduce f seed) ob))) +(defn pairwise + "Groups pairs of consecutive emssions together and emits them as + a javascript array." + [ob] + (ops/pipe (ops/pairwise) ob)) + (defn scan "Applies an accumulator function over an observable sequence and returns each intermediate result. Same as reduce but with diff --git a/src/beicon/v2/operators.cljs b/src/beicon/v2/operators.cljs index 7d3b6d5..30ac0b3 100644 --- a/src/beicon/v2/operators.cljs +++ b/src/beicon/v2/operators.cljs @@ -130,6 +130,11 @@ ([f seed] (rx/reduce #(f %1 %2) seed))) +(def ^function pairwise + "Groups pairs of consecutive emssions together and emits them as + a javascript array." + rx/pairwise) + (defn scan "Applies an accumulator function over an observable sequence and returns each intermediate result. Same as reduce but with diff --git a/test/beicon/tests/v2_test.cljs b/test/beicon/tests/v2_test.cljs index d639f1f..be72bc2 100644 --- a/test/beicon/tests/v2_test.cljs +++ b/test/beicon/tests/v2_test.cljs @@ -254,6 +254,13 @@ (drain! s #(do (t/is (= % [[1 2 4 5 6]])) (done)))))) +(t/deftest observable-pairwise + (t/async done + (let [s (rx/from [1 2 3 4 5]) + ps (rx/pairwise s)] + (t/is (rx/observable? ps)) + (drain! ps #(t/is (= (map vec %) [[1 2] [2 3] [3 4] [4 5]]))) + (rx/on-end ps done)))) (t/deftest observable-scan (t/async done