File tree Expand file tree Collapse file tree 2 files changed +39
-2
lines changed
language-adaptors/rxjava-clojure/src
main/clojure/rx/lang/clojure
test/clojure/rx/lang/clojure Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Original file line number Diff line number Diff line change 7
7
interleave interpose into
8
8
keep keep-indexed
9
9
map mapcat map-indexed
10
- merge next nth partition reduce reductions
10
+ merge next nth partition-all reduce reductions
11
11
rest seq some sort sort-by split-with
12
12
take take-while throw ])
13
13
(:require [rx.lang.clojure.interop :as iop]
618
618
([^Observable xs index not-found]
619
619
(.elementAtOrDefault xs index not-found)))
620
620
621
- ; TODO partition. Use window
621
+ (defn ^Observable partition-all
622
+ " Returns an Observable of Observables of n items each, at offsets step
623
+ apart. If step is not supplied, defaults to n, i.e. the partitions
624
+ do not overlap. May include partitions with fewer than n items at the end.
625
+
626
+ See:
627
+ clojure.core/partition-all
628
+ rx.Observable/window
629
+ "
630
+ ([n ^Observable xs] (.window xs (int n)))
631
+ ([n step ^Observable xs] (.window xs (int n) (int step))))
622
632
623
633
(defn ^Observable reduce
624
634
([f ^Observable xs] (.reduce xs (iop/fn* f)))
Original file line number Diff line number Diff line change 416
416
(let [in [:q :r :s :t :u ]]
417
417
(is (= (rest in) (b/into [] (rx/rest (rx/seq->o in)))))))
418
418
419
+ (deftest test-partition-all
420
+ (are [input-size part-size step] (= (->> (range input-size)
421
+ (partition-all part-size step))
422
+ (->> (range input-size)
423
+ (rx/seq->o )
424
+ (rx/partition-all part-size step)
425
+ (rx/map #(rx/into [] %))
426
+ (rx/concat* )
427
+ (b/into [])))
428
+ 0 1 1
429
+ 10 2 2
430
+ 10 3 2
431
+ 15 30 4 )
432
+
433
+ (are [input-size part-size] (= (->> (range input-size)
434
+ (partition-all part-size))
435
+ (->> (range input-size)
436
+ (rx/seq->o )
437
+ (rx/partition-all part-size)
438
+ (rx/map #(rx/into [] %))
439
+ (rx/concat* )
440
+ (b/into [])))
441
+ 0 1
442
+ 10 2
443
+ 10 3
444
+ 15 30 ))
445
+
419
446
(deftest test-reduce
420
447
(is (= (reduce + 0 (range 4 ))
421
448
(b/first (rx/reduce + 0 (rx/seq->o (range 4 )))))))
You can’t perform that action at this time.
0 commit comments