This is a real corner case, so probably not worth much attention. I was experimenting with writing a version of tree-seq using reduction rather than sequences. Here's what I came up with:
`
(defn tree-producer [branch? children node]
(let [recurse #(tree-producer branch? children %)]
(reify clojure.lang.IReduceInit
(reduce [this rf rval]
(let [rval (rf rval node)]
(cond
(reduced? rval) @rval
(branch? node) (transduce (mapcat recurse) rf rval (children node))
:else rval))))))
`
However, using it resulted in an exception:
user=> (into [] (tree-producer seq? identity '((1 2 (3)) (4))))
Execution error (ArityException) at temp$tree_producer$reify__7693/reduce (temp.clj:129).
Wrong number of args (1) passed to: clojure.core/preserving-reduced/fn--8743
The exception is not thrown if preserving-reduced is given a 1 argument arity, ie:
`
(defn ^:private preserving-reduced
[rf]
(fn ( [rval] rval)
( [rval x]
(let [ret (rf rval x)]
(if (reduced? ret)
(reduced ret)
ret)))))
`