Re: Getting index of char from end

2011-11-12 Thread Jestan Nirojan
st-indexof \c)) Regards. Jestan Nirojan On Nov 12, 12:07 pm, Jestan Nirojan wrote: > I think regex free solution is best for this > > (defn last-indexof [s c] >    (->> s (filter #(= c %)) count dec) > > On Nov 12, 3:36 am, "jongwon.choi" wrote: > > > &g

Re: Getting index of char from end

2011-11-11 Thread Jestan Nirojan
I think regex free solution is best for this (defn last-indexof [s c] (->> s (filter #(= c %)) count dec) On Nov 12, 3:36 am, "jongwon.choi" wrote: > Hi > > I'm wondering the best way to express: > >      (position #\a "abba" :from-end t) > > Should I use interop? > >      (.lastIndexOf "abb

Re: Recursively convert Java Map to Clojure Map

2011-10-15 Thread Jestan Nirojan
Your solution worked, about 4x~5x improvement. Thanks a lot BG. regards. -Jestan Nirojan On Oct 15, 2:10 pm, Baishampayan Ghose wrote: > > I have a Java Map contains Map of Maps/List (JSON like map) and have > > to convert to Clojure map (This happens at Java - Clojure Interop), S

Recursively convert Java Map to Clojure Map

2011-10-15 Thread Jestan Nirojan
ll [f form] (walk-coll (partial postwalk-coll f) f form)) (defn as-clj-map [m] (let [f (fn [[k v]] (if (string? k) [(keyword k) v] [k v]))] (postwalk-coll (fn [x] (if (instance? java.util.Map x) (into {} (map f x)) x)) m))) Thanks and regards. -Jestan Nirojan -- You received this message b

Re: Sum on a list of maps

2011-10-14 Thread Jestan Nirojan
ll (map (fn [ {v :value t :type } ] {t v})) (apply (partial merge-with +))) Jestan Nirojan. On Oct 15, 12:46 am, Dave Ray wrote: > Someone cleverer than me to post the built-in function that already > does exactly what you want, but here's one way: > > (defn sum-by-ty

Re: Sum on a list of maps

2011-10-14 Thread Jestan Nirojan
I would write like this (defn sum-by-type [coll] (->> coll (map (fn [ {v "Value" t "Type" } ] {t (read-string v) })) (apply (partial merge-with + If the map is keyword int map, it will be simpler than above (defn sum-by-type [coll] (->> coll (map (fn [ {v :value t :type } ] {t v