You can use the *pad* argument in *partition* to add x as the value of :zone-5, like *(partition 2 2 [x] params)*. (Note you have to supply *step* if you supply *pad*.) Then you don't need the *or* or the *(last params)*.
Also, like Billy did, you can use *some* instead of (*first (filter (complement nil?)...* The confusing thing about *some* is that it doesn't return the first value for which the predicate is true, it returns the value of the predicate the first time it is truthy. So using it to return the first one that isn't nil works perfectly. And the partial function doesn't really help you here because you already have access to x where you need to call your function. If you make those 3 changes, you'll have: (defn quantize [x params] (some (fn [[b c]] (if (<= x c) b)) (partition 2 2 [x] params))) On Monday, February 17, 2014 9:04:22 PM UTC-8, Laurent Droin wrote: > > Hmmm, looks like I can replace > > #(not (nil? %)) > > by > (complement nil?) > > which seems more elegant. > > Also, it looks like I don't need that (into [] ), which will keep the code > cleaner. > > I think I could also get rid of the (or) by always adding "(last params)" > at the end of the sequence from which I pick the first non null element. > The problem with this is that I need to make sure I add this element at the > end of the collection, and map returns a list, which means that I would > need to convert it into a vector if I want to use conj. > Or maybe there's a way to guarantee that I can add an element at the end > of the list. I know it's not cheap but I'm not sure if it will make a > significant difference for what I'm doing. > I think I could really abuse the "into" function and that doesn't seem > quite right. > -- 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/groups/opt_out.