Re: How to do multiple trys

2010-08-01 Thread abhinav sarkar
Thanks to everyone for their suggestions. This is what I have used finally: (defn parse-date [date-str] (when-not (blank? date-str) (let [clean-date-str (trim date-str) parse-or-nil (fn [format] (try (.parse format clean-date-str)

Re: How to do multiple trys

2010-07-30 Thread ataggart
Untested, but maybe this: (def- parse-date [date-str] (when-not (blank? date-str) (let [date-str (trim date-str)] (take 1 (filter identity (map #(try (.parse % date-str) (catch ParseException e nil)) [full-date-format date-format-wo-tz short-date-format-wo

Re: How to do multiple trys

2010-07-30 Thread Armando Blancas
parse-or-nil can be avoided by calling parse with an additional argument (ParsePosition. 0), in which case parse returns nil on failure. On Jul 30, 6:21 am, Laurent PETIT wrote: > Hi, > > 2010/7/30 abhinav sarkar > > > > > > > Hi, > > I am just starting to learn Clojure by writing a small librar

Re: How to do multiple trys

2010-07-30 Thread Laurent PETIT
Hi, 2010/7/30 abhinav sarkar > Hi, > I am just starting to learn Clojure by writing a small library. I came > across a situation in which I have to parse a String for getting a Date. Now > the string can be in one of the three formats. So I wrote this functions to > parse it: > > (def #^{:privat

How to do multiple trys

2010-07-30 Thread abhinav sarkar
Hi, I am just starting to learn Clojure by writing a small library. I came across a situation in which I have to parse a String for getting a Date. Now the string can be in one of the three formats. So I wrote this functions to parse it: (def #^{:private true :tag SimpleDateFormat} full-date-forma