From eaf439a16a4c5771f2fb7a2bc836e66624e61e9e Mon Sep 17 00:00:00 2001 From: Miguel de Benito Delgado Date: Tue, 17 Jun 2025 10:54:16 +0200 Subject: [PATCH 1/4] Add pairwise operator --- src/beicon/v2/core.cljs | 8 +++++++- src/beicon/v2/operators.cljs | 5 +++++ test/beicon/tests/v2_test.cljs | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/beicon/v2/core.cljs b/src/beicon/v2/core.cljs index 2c84f4f..b15fc9b 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) 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 From 641372a52cc263b8fd25ba0d66231e50d0120aba Mon Sep 17 00:00:00 2001 From: Miguel de Benito Delgado Date: Tue, 17 Jun 2025 10:57:06 +0200 Subject: [PATCH 2/4] Add some gitignores for calva users --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) 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 From c03854e22a4f6453f5878891d6cab263dc698e32 Mon Sep 17 00:00:00 2001 From: Miguel de Benito Delgado Date: Tue, 17 Jun 2025 10:57:41 +0200 Subject: [PATCH 3/4] Add two words about testing --- CONTRIBUTING.md | 10 ++++++++++ 1 file changed, 10 insertions(+) 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. From 2631ccf28a291f852843ecf5686b87a42f4730c6 Mon Sep 17 00:00:00 2001 From: Miguel de Benito Delgado Date: Sat, 21 Jun 2025 20:41:32 +0200 Subject: [PATCH 4/4] Fix call to rxjs pairwise --- src/beicon/v2/core.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/beicon/v2/core.cljs b/src/beicon/v2/core.cljs index b15fc9b..9e4b50f 100644 --- a/src/beicon/v2/core.cljs +++ b/src/beicon/v2/core.cljs @@ -493,7 +493,7 @@ "Groups pairs of consecutive emssions together and emits them as a javascript array." [ob] - (ops/pipe (ops/pairwise ob) ob)) + (ops/pipe (ops/pairwise) ob)) (defn scan "Applies an accumulator function over an observable sequence and