i assume you are coming from a java background? if so, every time you wrote this:
Result result = null; for (Stuff s:stuffList) { if (result ==null) result = ... result.cuddleWith(s); } return result a reducer would have been a functional alternative to this Am 21.08.2012 13:04, schrieb Jim - FooBar();: > Dear all, > > Can anyone redirect me to some 'real code' using reducers? I say > 'real-code' cos I don't consider (r/fold + [1 2 3 4 5]) to be a > realistic example of usage...also, apart from Rich's blogs, I'm having a > hard time finding resources explaining the role of the > combining/reducing fns. THe way I understand it, the entire reducers > lib is only applicable (with benefits) to tree-like structures and so, > the reducing fn is the one applied on the leaves to make them fewer > (reduce them) and the combining fn is the one that essentially > propagates the reductions back up the tree (combines them)... Can anyone > confirm this understanding of mine? > > > Assuming I'm thinking about it the right way, I 'd like to build a > map-tree (nested maps) where the leaves will be reduced using 'max-key' > and combined back up using 'r/cat' , which apparently is a: > "high-performance combining fn that yields the catenation of the > reduced values.". Does that make any sense whatsoever? I'm really > struggling to replace (apply max-key #(...) (:children tree)) with some > form of (r/fold r/cat #(max-key (fn [e] ....)) (:children tree))... > > I'd love to see some proper usage of reducers so I can understand what > is going on...From all the videos I've watched, I 've understood that > the algorithm I'm implementing (minimax) is an ideal candidate for > reducers - however I've still not managed to tame them...any > help/pointers will be massively appreciated! :-) > > Thanks in advance... > > 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 -- -- 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