weavejester / medley

A lightweight library of useful Clojure functions
Eclipse Public License 1.0
865 stars 66 forks source link

medley/join may occur StackOverflowError in rare cases #66

Closed velios closed 9 months ago

velios commented 1 year ago
(reduce (fn [acc coll]
          (medley/join [acc coll]))
        []
        (map (fn [v]
               [v v])
             (range 10000)))

Execution leads to StackOverflowError due using concat

Same described https://stuartsierra.com/2015/04/26/clojure-donts-concat

Rare case, but may happen

More examples here https://gist.github.com/stuartsierra/9982776

weavejester commented 1 year ago

Sure, but this seems unavoidable for the same reasons its unavoidable in concat? Or do you have a solution?

velios commented 1 year ago

(reduce (fn [acc coll] (into acc coll)) [] (map (fn [v] [v v]) (range 10000)))

This solution avoids the described problems on my project, but it needs to be improved, if at all suitable in the case of medley/join

weavejester commented 1 year ago

That solution works because into is not lazy.