Skip to content

Pairwise operator #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
.shadow-cljs
.yarn/*
/*-init.clj
/.calva
/.clj-kondo
/.cpcache
/.lein-*
/.lsp
/.nrepl-port
/.rebel*
/checkouts
Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 7 additions & 1 deletion src/beicon/v2/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/beicon/v2/operators.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/beicon/tests/v2_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down