5 ms·
It's doesn't cast doubt on the examples at all, your code is less generic: (defn has-uppercase? [string] (some #(Character/isUpperCase %) string)) This
by swannodette 15y ago
It's doesn't cast doubt on the examples at all, your code is less generic:
(defn has-uppercase? [string]
(some #(Character/isUpperCase %) string))
This code can deal with any sequence of characters: String, Array, PersistentList, PersistentVector, Cons, LazySequence, etc. Your example only deals with String.
- efsavage 15y agoFair enough, but mine was not an alternate to his Clojure code, but to his Java code (which only checks String). Perhaps he should have focused on the functional efficiency like you did, rather than just bloated lines of code.
- seabee 15y agoIt's still not an alternate to the Java, since there are more upper-case characters than the 26 your regex matches. But I'm sure there is an appropriate Unicorn character class you could use instead.
- palish 15y ago... A String is a sequence of characters. Why would you want a "list of characters"? That's called a String.
- barrydahlberg 15y agoUseful if you are composing the function with others which may not be built specifically for strings, e.g. filter, map etc.