And just to add a pointer in case anybody's interested in opting in to this behaviour in a custom type, it's possible to do so by implementing clojure.core.protocols/IKVReduce (data.avl does this) or clojure.lang.IKVReduce (the iface implemented by built-in maps; clojure.core provides implementation of clojure.core.protocols/IKVReduce targeting clojure.lang.IKVReduce). Of course then it is the responsibility of that custom implementation to implement reduce-kv's semantics correctly.
Cheers, Michał On 30 April 2016 at 02:18, Timothy Baldridge <[email protected]> wrote: > Yes, and it happens for most collections. Vectors, maps, etc. There's even > a fast path for reduce-kv on maps that doesn't create key value entry > objects. > > > Timothy > > On Fri, Apr 29, 2016 at 6:06 PM, Mark Engelberg <[email protected]> > wrote: > >> So you're saying that this is an optimization that is automatically >> called when you invoke Clojure's standard reduce function on something like >> a vector? >> >> >> On Fri, Apr 29, 2016 at 1:14 PM, Alex Miller <[email protected]> wrote: >> >>> The main internal protocol is really CollReduce for collections that can >>> reduce themselves. InternalReduce is for concrete seq implementations that >>> can reduce themselves. >>> >>> For cases where you are creating new things, you can also plug in a >>> little more easily by implementing the IReduceInit (reduce with an init >>> value) or IReduce (extends IReduceInit for the case where an init value is >>> not supplied) Java interfaces. I would generally prefer these if you are >>> creating a new thing. >>> >>> >>> On Friday, April 29, 2016 at 2:41:10 PM UTC-5, Camilo Roca wrote: >>>> >>>> puzzler, >>>> No, Clojure actually has quite a lot of protocols for reducing >>>> "things". But they are so many that I got lost in which does what and how, >>>> so I wanted a clarification on the subject. >>>> >>>> Alex miller, excellent answer already gave me some overview of the >>>> topic. >>>> >>>> Here is a link to Clojure's protocols for reduce: >>>> https://github.com/clojure/clojure/blob/master/src/clj/clojure/core/protocols.clj >>>> <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fclojure%2Fclojure%2Fblob%2Fmaster%2Fsrc%2Fclj%2Fclojure%2Fcore%2Fprotocols.clj&sa=D&sntz=1&usg=AFQjCNEw9QmBOeBqHioMJEhGeBYF_N2gTA> >>>> >>>> El viernes, 29 de abril de 2016, 21:17:42 (UTC+2), puzzler escribió: >>>>> >>>>> By "internal reduce", are you all talking about the Clojure reducers >>>>> library, or something else? >>>>> >>>>> -- >>> 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/d/optout. >>> >> >> -- >> 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/d/optout. >> > > > > -- > “One of the main causes of the fall of the Roman Empire was that–lacking > zero–they had no way to indicate successful termination of their C > programs.” > (Robert Firth) > > -- > 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/d/optout. > -- 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/d/optout.
