Init converter not called

I am writing a custom converter as an exercise, but I am surprised to see that its init-0-arity function is not called.

Why?

Is this related to which aggregation function I use? If so, what calls would the init function call and why aren't others?

(defn inc-xf [xf]
  "inc-xf should be equivalent to (map inc)"
  (fn
    ;; init
    ([]
     (println "init") ;; <- this is not called (???)
     (xf))

    ;; step
    ([result input]
     (println "step" result input)
     (xf result (inc input)))

    ;; completion
    ([result]
     (println "completion" result)
     (xf result))))

(transduce inc-xf
           +
           100
           [5 5 5])
+4
source share
1 answer

If you look at the implementation transduce, you will see what happens.

(defn transduce
  ;; To get the init value, (f) is used instead of ((xform f))
  ([xform f coll] (transduce xform f (f) coll))
  ([xform f init coll]
   ,,,))

Why, however, is more difficult to answer.

, , , clojure.core. , , transduce, init arity. jira , , :

, init arity xform . -

, ? ¯\_ (ツ) _/¯

+5

Source: https://habr.com/ru/post/1693788/


All Articles