为什么映射传感器的结果包含 greater-than-2 个参数?

Why does the result of a mapping transducer include greater-than-2 arities?

问题在标题里。下面我复制map的源码transducer-part:

([f]
  (fn [rf]
    (fn
      ([] (rf))
      ([result] (rf result))
      ([result input]
         (rf result (f input)))
      ([result input & inputs] ;why?
         (rf result (apply f input inputs))))))

这里是 link 到 the source of clojure.core 其中包含 map.

的定义

map 可以同时处理多个集合,为每个集合项调用带有参数的映射函数:

(map + [1 2 3] [4 5 6])
=> (5 7 9)

+ 函数为这些集合中的每对值调用一次,例如(+ 1 4)(+ 2 5)(+ 3 6)。非换能器版本看起来像 this.

map 换能器的工作方式相同:

(sequence (map +) [1 2 3] [4 5 6])
=> (5 7 9)

[map] Returns a lazy sequence consisting of the result of applying f to the set of first items of each coll, followed by applying f to the set of second items in each coll, until any one of the colls is exhausted. Any remaining items in other colls are ignored. Function f should accept number-of-colls arguments. Returns a transducer when no collection is provided.