Hi all,
so I was playing with the reducers library today and I think I've
identified the critical spot where my code can be parallelized. after
all i am building a tree and i am using a map that nests. According to
all the posts this is ideal situation for reducing...anyway, assuming
I'm correct in thinking that the following line is culprit,
(->> (:children tree) ;;a lazy-seq of maps where :children is a
lazy-seq of maps etc
(apply max-key (evaluator eval-fn))
(:node)) ;;return the best state
I thought about doing this:
(->> (:children tree)
(vec) ;;make it a vector so it it parallelisable
(r/fold #(max-key (evaluator eval-fn) %))
(:node))
but that wont work cos I'm not supplying a combing fn and the reducing
one is used instead, which cannot take 0 args. Now, obviously I need to
use r/monoid to construct a combining fn but i don't understand what to
pass in as an identity value ("ctor") to be called with no args at the
bottom. So my question is foldable! (2-fold):
1. How do I construct a combining fn out of 'max-key' and is there an
idiom or a pattern for doing so?
2. Since the docs say that r/fold will only work in parallel for
tree-like structures like maps and vectors, I've passing the
lazy-seq through 'vec'. Does that make any sense whatsoever or will
the entire thing be realized before it ever reaches r/fold?
Any insights are very much welcome...I am just starting playing around
with reducers but it seems like the situation I'm in is the perfect
candidate for this sort of thing and I want to know more! Also without
this, my chess minimax searching is hopeless!
Jim
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en