Hello,

your function does not follow the contract of fold. What you provided is 
basically the reduce function, but it doesn't work together with fold. For 
fold you need to merge the different maps you created in the subtasks. So 
the combine function must look different.

(defn my-frequencies
  [coll]
  (r/fold
    (fn
      ([] {})
      ([a b] (merge-with + a b)))
    #(update-in %1 [%2] (fnil inc 0))
    {}
    coll))

Compare this example. The contract for the combine function requires that 
the combine function may be called with zero arguments to return the 
seeding value for the subtask. In our case an empty map. (This is were your 
example blows up.) To combine two maps we use merge-with. The update-in is 
basically the reduce function. The reducers library provides the monoid 
helper to ease the pain a little. (Although it doesn't buy us much in your 
example.)

(defn my-frequencies
  [coll]
  (r/fold
    (r/monoid
      #(merge-with + %1 %2)
      (constantly {}))
    #(update-in %1 [%2] (fnil inc 0))
    {}
    coll))

Additionally you cannot use transients at the moment with fold.

Kind regards
Meikel

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to