clojure / clojure-site

clojure.org site
https://clojure.org
Eclipse Public License 1.0
250 stars 272 forks source link

reducers example isn't parallel #377

Open vemv opened 5 years ago

vemv commented 5 years ago

The following example included in https://clojure.org/reference/reducers won't run in parallel because range is a seq:

(r/foldcat (r/filter even? (r/map inc (range 100000))))

It is confusing to find a "no-gain" example in a page explaining reducers.

Consequently, I'd suggest instead:

;; `vec` is there since seqs don't support parallel folding
(r/foldcat (r/filter even? (r/map inc (vec (range 100000)))))

Perhaps the comment would duplicate some information already in the page (If a collection does not support folding, it will fall back to non-parallel reduce instead.), but newcomers probably will appreciate a reminder (and an example).

puredanger commented 3 years ago

Maybe should go further to find better example here.