Skip to content

Add operators start-with and end-with #59

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 1 commit 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
16 changes: 16 additions & 0 deletions src/beicon/v2/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,22 @@
[ob]
(ops/pipe (ops/merge-all 1) ob))

(defn start-with
"Emits the provided value(s) before any other emissions
from the source Observable."
[& args]
(let [values (butlast args)
ob (c/last args)]
(ops/pipe (apply ops/start-with values) ob)))

(defn end-with
"Emits the provided value(s) after all other emissions
from the source Observable."
[& args]
(let [values (butlast args)
ob (c/last args)]
(ops/pipe (apply ops/end-with values) ob)))

(defn skip
"Bypasses a specified number of elements in an
observable sequence and then returns the remaining
Expand Down
12 changes: 12 additions & 0 deletions src/beicon/v2/operators.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@
[f]
(rx/concatMap #(f %2 %1)))

(def ^function start-with
"Returns an observable sequence that upon subscription emits the
specified values before it begins to emit the elements of the
source observable sequence."
rx/startWith)

(def ^function end-with
"Returns an observable sequence that emits the elements of the
source observable and then emits the specified values after the
source completes."
rx/endWith)

(def ^function skip
"Bypasses a specified number of elements in an
observable sequence and then returns the remaining
Expand Down
18 changes: 18 additions & 0 deletions test/beicon/tests/v2_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,24 @@
(drain! sample #(t/is (= % [2 3 4 5])))
(rx/on-end sample done))))

(t/deftest observable-start-with
(t/async done
(let [nums (rx/from [1 2 3])
s (rx/start-with 0 nums)
u (rx/start-with -2 -1 s)]
(t/is (rx/observable? u))
(drain! u #(t/is (= % [-2 -1 0 1 2 3])))
(rx/on-end u done))))

(t/deftest observable-end-with
(t/async done
(let [nums (rx/from [1 2 3])
s (rx/end-with 4 (rx/from nums))
u (rx/end-with 5 6 (rx/from s))]
(t/is (rx/observable? u))
(drain! u #(t/is (= % [1 2 3 4 5 6])))
(rx/on-end u done))))

(t/deftest subject-as-ideref
(t/async done
(let [nums (rx/from [1 1 1 2 3 4 5])
Expand Down