Fork me on GitHub
#missionary
<
2022-10-15
>
Dustin Getz12:10:26

is there an easy way to turn Java lang interable into a discrete flow or should I loop/recur and .next .hasNext

Dustin Getz12:10:29

or, how to turn a slow lazy seq into discrete flow

Dustin Getz12:10:26

(defn iterator-consumer [^java.util.Iterator iterator]
  (m/ap
    (while (m/?? (m/enumerate (when (m/? (m/via m/blk (.hasNext iterator))) [false true]))))
    (.next iterator)))

leonoel12:10:18

this pattern works yes, just make sure to wrap blocking ops with via

xificurC13:10:57

This is relatively old, m/amb would simplify it

Dustin Getz13:10:58

(defn iterator-consumer [^java.util.Iterator iterator]
  (m/ap
    (loop []
      (if (m/? (m/via m/blk (.hasNext iterator)))
        (amb (.next iterator) (recur))
        (amb)))))
?

xificurC14:10:22

And m/via m/blk only makes sense if your iterator blocks

xificurC14:10:53

Didn't get Leo's post or your new code until now.. Android client is weird

leonoel14:10:31

if nonblocking you can just seed the iterable

👍 1
Dustin Getz14:10:55

what if I have a slow lazy seq (attached to a database iterator)

Dustin Getz14:10:09

cc/reduce inside an m/observe? using ! inside the reducing function to seed the stream

Dustin Getz14:10:59

or just drop to low-level flow interface

leonoel14:10:36

use the blocking iterable pattern, replace hasNext with seq and next with first/rest

👍 1
Dustin Getz19:10:56

for the record

teodorlu09:10:27

@U09K620SG out of curiosity - do you use your dustingetz.scratch namespace in a mutable fashion? I mean - do you have a static project you use for constant, minor experimentation stuff? Asking because I haven't found a workflow that works for me for "small stuff". I end up either creating lots and lots of projects -- or I have a scratch project that just accumulates so much cruft it gets slow and tedious, just adding more and more dependencies and namespaces.

Dustin Getz01:10:20

i like a scratch folder and :scratch alias in every big project and i commit anything interesting. i have a default scratch file that is easy to open with the core project requires preset and then rename and commit if worth saving, otherwise discard changes

👍 1
teodorlu05:10:13

Interesting. That's really helpful. Thank you! I might steal your workflow. Separating :scratch out as it's own alias sounds like a very good idea to enable exploration + avoid accidents. I also suspect it can help encourage exploration - and sharing those explorations.

🙂 1
nivekuil07:10:11

I do date-stamped scratch files, like a journal. helps track context associated with commits