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

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

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

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


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


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) ("clown" 5)) 


Ryan. 

On Sunday, December 1, 2013 9:21:14 PM UTC+2, 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  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.


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])))
 (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  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.


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


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


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



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


Any elegant solutions for this problem?

2013-12-01 Thread Ryan
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 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.