Fork me on GitHub
#missionary
<
2021-09-12
>
Johan00:09:13

(take 3 (repeatedly #(read-line))) This will run read-line 3 time, as expected. (m/? (m/reduce conj (m/eduction (comp (take 3)) (m/ap (m/?> (m/seed (repeatedly #(read-line)))))))) This will run read-line 5 time. Any idea why ?

leonoel20:09:37

This is a pipeline with 4 stages : seed -> ap -> eduction -> reduce. Each stage runs in parallel, between two successive stages there is a buffer (usually sized 1). Each stage tries to fill its output buffer as soon as there's room inside, in this example there's no asynchronous operation so the buffers get refilled immediately after transfer. When take gets the third value and triggers cancellation of upstream stages, the buffers are already filled with the next values.