Re: Any elegant solutions for this problem?

2013-12-01 Thread Ryan
Nice James, I like it :) Ryan On Sunday, December 1, 2013 10:02:32 PM UTC+2, James Reeves wrote: > > There's also: > > (->> xs > (partition-by string?) > (partition 2) > (mapcat (fn [[[s] xs]] (for [x xs] [s x] > > > - James > > > On 1 December 2013 19:39, Ryan > wrote: > >> Ha

Re: Any elegant solutions for this problem?

2013-12-01 Thread James Reeves
There's also: (->> xs (partition-by string?) (partition 2) (mapcat (fn [[[s] xs]] (for [x xs] [s x] - James On 1 December 2013 19:39, Ryan wrote: > Haha, no worries, it happens :) > > That seems to work nice as well! > > Ryan > > > On Sunday, December 1, 2013 9:36:47 PM UT

Re: Any elegant solutions for this problem?

2013-12-01 Thread Ryan
Haha, no worries, it happens :) That seems to work nice as well! Ryan On Sunday, December 1, 2013 9:36:47 PM UTC+2, john walker wrote: > > I swear english is my first language. This one isn't elegant, but at least > you know you aren't alone: > > (->> ["foo" 1 "bar" 10 20 "clown" 5] > (par

Re: Any elegant solutions for this problem?

2013-12-01 Thread Ryan
Thanks both for your answers. @Ben, that seems to do it. I was trying to make it a bit "nicer" but failed @john, that was my original approach but it does not produce what I want. The result of that is (("foo" 1) ("bar" 10 20) ("clown" 5)) but I need (("foo" 1) ("bar" 10) ("bar" 20) ("clow

Re: Any elegant solutions for this problem?

2013-12-01 Thread john walker
I swear english is my first language. This one isn't elegant, but at least you know you aren't alone: (->> ["foo" 1 "bar" 10 20 "clown" 5] (partition-by string?) (partition 2) (map #(apply concat %)) (map #(let [x (first %)] (for [y (rest %)] [x y])

Re: Any elegant solutions for this problem?

2013-12-01 Thread john walker
Use partition-by http://clojuredocs.org/clojure_core/clojure.core/partition-by On Sunday, December 1, 2013 1:57:52 PM UTC-5, Ryan wrote: > > Hi all, > > I have a vector which contains an unknown number of repetitions of the > following pattern: > > String, followed by 1 or more integers > > For

Re: Any elegant solutions for this problem?

2013-12-01 Thread john walker
Sorry, I spoke without seeing that you were aware of partition-by. Here's one that isn't vectorized. (def v ["foo" 1 "bar" 10 20 "clown" 5]) (->> v (partition-by string?) (partition 2) (map #(apply concat %))) On Sunday, December 1, 2013 2:10:04 PM UTC-5, Ben wrote: > > user=> (def v

Re: Any elegant solutions for this problem?

2013-12-01 Thread Ben Wolfson
user=> (def v ["foo" 1 "bar" 2 3 "baz" 4]) #'user/v user=> (first (reduce (fn [[res s] e] (if (string? e) [res e] [(conj res [s e]) s])) [[] nil] v)) [["foo" 1] ["bar" 2] ["bar" 3] ["baz" 4]] On Sun, Dec 1, 2013 at 10:57 AM, Ryan wrote: > Hi all, > > I have a vector which contains an unknown num