Roelof, Unless supplied with an initial value, reduce will use the first value from the collection you supply - every sequence which doesn't start with "1" will give you the wrong answer.
Take care, Moe On Sat, Oct 3, 2015 at 9:40 PM, Roelof Wobben <wobbenroe...@gmail.com> wrote: > Hello, > > I have to make a function which counts a collection without using count. > > So I came up with this : > > (fn [coll] (reduce (fn [counter _ ] (inc counter)) coll))) > > it works well with coll is [ 1 2 3] > > but it fails with "Hello World" > > How can I improve my code to work in both cases. > > Please , do not only give the answer but rather explain how I can make > this work. > So I learn a lot and not do only a copy/paste. > > Roelof > > -- > 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 unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > 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 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.