reduce - How can I define a function with uncertain argument in clojure -


i wondering how define function uncertain argument in clojure. here example:

(reduce + [1 2 3 4]) => 10 (reduce list [1 2 3 4]) => (1 2 3 4) (reduce inc [3]) => 3 

i want define reduce function (reduce func coll) can apply func first 2 elements in coll, apply func result of first 2 elements , third element, until elements used. puzzled different source code of reduce? have no idea how define function far. there can me figure out problem or give me tips? appreciate that!

to clear, asking this:

apply func first 2 elements in coll, apply func result of first 2 elements , third element,

that reduce does:

user> (reduce list [1 2 3 4]) (((1 2) 3) 4) 

the list of first 2 (1 2). then, apply list function result , next element, 3 , ((1 2) 3). , continue until elements used up.

i suspect not asking question correctly or clearly.

--

i see asking not how create function want different reduce rather how implement reduce yourself?

if case, typically functional designs involved recursion, split sequence head , tail, process it, , recur on tail, splits again head , tail, until there no more tail left.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -