Skip to content

Commit 1711040

Browse files
committed
through exercise 24
1 parent 3a079fe commit 1711040

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

rxjava/expt1/src/expt1/core.clj

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,7 @@
583583
(.map (fn [vid] {:id (vid "id") :title (vid "title")}))
584584

585585
subscribe-collectors
586-
pdump
587-
)
586+
pdump)
588587

589588
;;; in JavsScript, interpret "pair" to mean "an object with two
590589
;;; properties"
@@ -628,8 +627,7 @@
628627
(.map (fn [vid] (vid "id")))
629628

630629
subscribe-collectors
631-
pdump
632-
)
630+
pdump)
633631

634632
;;; Javascript
635633
;;;
@@ -712,6 +710,7 @@
712710
asynchronous-observable
713711

714712
(.mapMany (fn [genres] (-> (genres "videos") asynchronous-observable)))
713+
715714
(.mapMany (fn [vid] (-> (vid "boxarts") asynchronous-observable
716715
(.filter (fn [art] (and (== 150 (art "width"))
717716
(== 200 (art "height")))))
@@ -775,6 +774,34 @@
775774
;;; Exercise 24: Retrieve each video's id, title, middle interesting moment
776775
;;; time, and smallest box art url.
777776

777+
(-> (jslurp "Exercise_24.json")
778+
asynchronous-observable
779+
780+
(.mapMany (fn [genre] (-> (genre "videos") asynchronous-observable)))
781+
(.mapMany (fn [vid]
782+
(let [arts (-> (vid "boxarts")
783+
asynchronous-observable
784+
(.reduce (fn [c p]
785+
(if (< (* (c "height") (c "width"))
786+
(* (p "height") (p "width")))
787+
c p))))
788+
moments (-> (vid "interestingMoments")
789+
asynchronous-observable
790+
(.filter (fn [moment] (= (moment "type") "Middle"))))
791+
]
792+
(Observable/zip
793+
arts
794+
moments
795+
(fn [art moment]
796+
{:id (vid "id")
797+
:title (vid "title")
798+
:time (moment "time")
799+
:url (art "url")}
800+
)))
801+
))
802+
803+
subscribe-collectors
804+
pdump)
778805

779806
;;; Javascript
780807
;;;

0 commit comments

Comments
 (0)