(reduce f coll)
(reduce f val coll)
f should be a function of 2 arguments. If val is not supplied,
returns the result of applying f to the first 2 items in coll, then
applying f to that result and the 3rd item, etc. If coll contains no
items, f must accept no arguments as well, and reduce returns the
result of calling f with no arguments. If coll has only 1 item, it
is returned and f is not called. If val is supplied, returns the
result of applying f to val and the first item in coll, then
applying f to that result and the 2nd item, etc. If coll contains no
items, returns val and f is not called.
Source
(defn
reduce
"f should be a function of 2 arguments. If val is not supplied,\n returns the result of applying f to the first 2 items in coll, then\n applying f to that result and the 3rd item, etc. If coll contains no\n items, f must accept no arguments as well, and reduce returns the\n result of calling f with no arguments. If coll has only 1 item, it\n is returned and f is not called. If val is supplied, returns the\n result of applying f to val and the first item in coll, then\n applying f to that result and the 2nd item, etc. If coll contains no\n items, returns val and f is not called."
([f coll]
(cond
(implements? IReduce coll)
(-reduce coll f)
(array? coll)
(array-reduce coll f)
(string? coll)
(array-reduce coll f)
(native-satisfies? IReduce coll)
(-reduce coll f)
(iterable? coll)
(iter-reduce coll f)
:else
(seq-reduce f coll)))
([f val coll]
(cond
(implements? IReduce coll)
(-reduce coll f val)
(array? coll)
(array-reduce coll f val)
(string? coll)
(array-reduce coll f val)
(native-satisfies? IReduce coll)
(-reduce coll f val)
(iterable? coll)
(iter-reduce coll f val)
:else
(seq-reduce f val coll))))