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]
>      (partition-by string?)
>      (partition 2)
>      (map #(apply concat %))
>      (map #(let [x (first %)]
>              (for [y (rest %)]
>                [x y])))
>      (reduce into []))
>
> On Sunday, December 1, 2013 2:21:14 PM UTC-5, john walker wrote:
>>
>> 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 ["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 <areka...@gmail.com> 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 example:
>>>>
>>>> String
>>>> Integer
>>>> String
>>>> Integer
>>>> Integer
>>>> String
>>>> Integer
>>>> Integer
>>>> Integer
>>>> String
>>>> Integer
>>>>
>>>> What I am trying to do is to create a vector of pairs which each pair 
>>>> will be the string and the integers followed.
>>>>
>>>> Real example:
>>>>
>>>> foo
>>>> 1
>>>> bar
>>>> 10
>>>> 20
>>>> clown
>>>> 5
>>>>
>>>> should convert to:
>>>>
>>>> [[foo 1] [bar 10] [bar 20] [clown 5]]
>>>>
>>>> I did try to play around with partition-by, partition and instance? but 
>>>> I couldn't get it quite right. 
>>>>
>>>> Thank you for your time
>>>>
>>>> -- 
>>>> -- 
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Clojure" group.
>>>> To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com.
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>
>>>
>>>
>>> -- 
>>> Ben Wolfson
>>> "Human kind has used its intelligence to vary the flavour of drinks, 
>>> which may be sweet, aromatic, fermented or spirit-based. ... Family and 
>>> social life also offer numerous other occasions to consume drinks for 
>>> pleasure." [Larousse, "Drink" entry]
>>>
>>>  

-- 
-- 
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.

Reply via email to