This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-23
Channels
- # adventofcode (21)
- # announcements (4)
- # babashka (35)
- # beginners (36)
- # calva (76)
- # cider (16)
- # clj-kondo (24)
- # clj-on-windows (12)
- # clojure (70)
- # clojure-europe (7)
- # clojure-nl (13)
- # clojure-spec (3)
- # clojure-uk (3)
- # clojurescript (34)
- # conjure (11)
- # cursive (22)
- # datomic (30)
- # deps-new (2)
- # emacs (36)
- # fulcro (28)
- # gratitude (4)
- # honeysql (16)
- # hugsql (8)
- # introduce-yourself (6)
- # jobs (1)
- # malli (4)
- # missionary (6)
- # off-topic (129)
- # other-languages (34)
- # polylith (3)
- # reagent (9)
- # reitit (27)
- # releases (13)
- # remote-jobs (1)
- # reveal (1)
- # shadow-cljs (2)
- # tools-build (3)
- # tools-deps (18)
- # web-security (7)
- # xtdb (4)
hello, i just started playing with missionary today and i just can't figure out why only the last page is returned in the result, the code is based on this example: https://github.com/leonoel/missionary/wiki/Iterative-queries#the-solution:
(defn read-numbers []
(m/ap
(loop [first-number 0]
(let [numbers (m/?> (m/seed [(range first-number (inc first-number))]))
last-number (last numbers)]
(println "page:" numbers)
(if (< last-number 10)
(recur (inc last-number))
numbers)))))
(println "result:" (m/? (m/reduce conj (read-numbers))))
the output:
page: (0)
page: (1)
page: (2)
page: (3)
page: (4)
page: (5)
page: (6)
page: (7)
page: (8)
page: (9)
page: (10)
result: [(10)]
i wonder if i can ask for help figuring this outNot sure what kind of process you are trying to replicate with this example.
numbers is always going to be a seq of one element
last-number is always going to be = to first-number
(m/seed [(range first-number (inc first-number))])
This statement is always going to be something like -> (m/seed [
(some-int))])`
So unlike the example you never create multiple branch of the process.
If you want to return element while in the loop you can fork the process with amb> like so:
(defn read-numbers []
(m/ap
(loop [first-number 0]
(let [numbers (m/?> (m/seed [(range first-number (inc first-number))]))
last-number (last numbers)]
(println "page:" numbers)
(if (< last-number 10)
(m/amb> last-number (recur (inc last-number)))
numbers)))))
i wanted to create a minimal code example, but what i want is to get data from an api in multiple pages in this example the page size happens to be 1, this might have made it more confusing but your suggestion works, thank you! i'm embarrassed, but then i'm not sure where does the forking happen in the wiki code example, according to the comment it should happen at this point:
...
(m/?>))] ;; fork the process
...
but that part is replicated in my code and didn't work, what did i miss?