3 ms·
> preferring the immutable seq abstraction over iterators, and the core.async channel abstraction over promises/async iterators. do you know why javascript asy
by dominotw 7y ago
> preferring the immutable seq abstraction over iterators, and the core.async channel abstraction over promises/async iterators.
do you know why javascript async and co are superior to this?
- bikeshaving 7y agoI’m not sure if they’re superior. One thing that iterators can do which clojure lazy-seqs can’t is that with iterators, we have the concept of abrupt termination or return. In javascript, this is analogous to calling break within an iteration block, or calling the return method directly on the iterator. There is no equivalent concept with clojure seqs, meaning you can’t do things which tie down resources, like creating a database cursor and yielding the results. With a generator, you just make sure that you close the cursor by wrapping your yield operators in a `try/finally`. There is no equivalent for a recursive lazy-seq function, even though clojure does have `try/catch/finally` expressions. As far as why promises are superior to core.async you can refer to the list in my comment above.