Re: How to spec a plain map with exclusive groups of :req keys?

2016-06-15 Thread Den Semenenko
Alex, Walter, your tips are great for "validation". But I'm afraid this solution will lead to the custom generator... Anyway, thanks a lot. -- 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

Re: How to spec a plain map with exclusive groups of :req keys?

2016-06-15 Thread Walter van der Laan
You can wrap s/keys in s/and to add additional predicates, eg; (s/and (s/keys) #(or (::secret %) (and (::user %) (::pwd % You can also match the map with a predicate instead of s/keys, eg; #(and (map? %) (or (::secret %) (and (::user %) (::pwd % The the first option, with s/keys, will c

How to spec a plain map with exclusive groups of :req keys?

2016-06-15 Thread Alex Miller
Because spec embraces the idea of open maps, there is no provided support for checking that keys don't exist. To get this behavior you will need to use a custom predicate (probably s/and with s/keys to get its other checks). -- You received this message because you are subscribed to the Google

How to spec a plain map with exclusive groups of :req keys?

2016-06-15 Thread Den Semenenko
Can`t grok how to deffine exclusive groups of :req keys with spec/keys. For а doc sample (s/keys :req [(or ::secret (and ::user ::pwd))]) I expected, that valid combination is a ::secret *either* ::user and ::pwd. But a map with all of these keys is still valid... Any tips how to spec a plain

Re: algorithm help: extracting groups of consecutive ints from a sorted list

2014-03-28 Thread John Gabriele
Brilliant. Thanks, Shantanu! On Wednesday, March 19, 2014 12:09:56 AM UTC-4, Shantanu Kumar wrote: > > Something like this? > > (defn x [1 3 4 5 7 9 10 13]) > > (reduce (fn [a i] (let [y (last a) z (last y)] (if (and z (= (inc z) i)) > (conj (pop a) (conj y i)) (conj a [i] [] x) > > Shantanu

Re: algorithm help: extracting groups of consecutive ints from a sorted list

2014-03-28 Thread John Gabriele
Y'know, I'm guilty of not looking into flatland/useful enough. I'll have to try out codox on it, and see if that makes it easier for me to get acquainted with it. Thanks, Alex. On Wednesday, March 19, 2014 6:57:27 AM UTC-4, Alex Nixon wrote: > > Or use glue from flatland.useful.seq

Re: algorithm help: extracting groups of consecutive ints from a sorted list

2014-03-19 Thread Alex Nixon
Or use glue from flatland.useful.seq and: user=> (glue conj [] (fn [s n] (= (inc (last s)) n)) [1 3 4 5 7 9 10 13]) ([1] [3 4 5] [7] [9 10] [13]) On 19 March 2014 04:10, Shantanu Kumar wrote: > > > On Wednesday, 19 March 2014 09:39:56 UTC+5:30, Shantanu Ku

Re: algorithm help: extracting groups of consecutive ints from a sorted list

2014-03-18 Thread Shantanu Kumar
On Wednesday, 19 March 2014 09:39:56 UTC+5:30, Shantanu Kumar wrote: > > Something like this? > > (defn x [1 3 4 5 7 9 10 13]) > Sory for the typo. Should be (def x [1 3 4 5 7 9 10 13]) > > (reduce (fn [a i] (let [y (last a) z (last y)] (if (and z (= (inc z) i)) > (conj (pop a) (conj y i)) (

Re: algorithm help: extracting groups of consecutive ints from a sorted list

2014-03-18 Thread Shantanu Kumar
Something like this? (defn x [1 3 4 5 7 9 10 13]) (reduce (fn [a i] (let [y (last a) z (last y)] (if (and z (= (inc z) i)) (conj (pop a) (conj y i)) (conj a [i] [] x) Shantanu On Wednesday, 19 March 2014 08:26:43 UTC+5:30, John Gabriele wrote: > > If you've got a sorted list of numbers, fo

algorithm help: extracting groups of consecutive ints from a sorted list

2014-03-18 Thread John Gabriele
If you've got a sorted list of numbers, for example: [1 3 4 5 7 9 10 13] where some are consecutive, how can you pull out the consecutive runs? That is, either produce [1 [3 4 5] 7 [9 10] 13]; or maybe something like [[1 7 13] [3 4 5] [9 10]] ; (the first vec is the elements le

Re: groups-of

2008-12-19 Thread Chouser
On Fri, Dec 19, 2008 at 9:37 AM, Michael Wood wrote: > > On Fri, Dec 19, 2008 at 4:35 PM, Michael Wood wrote: >> >> hmmm... if I do this: >> >> user=> (partition 2 1 (iterate inc 1)) (.printStackTrace *e) >> >> it ends like this: >> >> [...] >> 57) (587257 587258) (587258 587259) (587259 587260

Re: groups-of

2008-12-19 Thread Michael Wood
On Fri, Dec 19, 2008 at 4:35 PM, Michael Wood wrote: > On Fri, Dec 19, 2008 at 4:32 PM, Rich Hickey wrote: >> >> On Dec 19, 8:59 am, "Michael Wood" wrote: [...] >>> There is a function called partition in Clojure's core.clj that does >>> this, except it does not pad, but rather discards any inc

Re: groups-of

2008-12-19 Thread Michael Wood
m Ruby >> > core/stdlib/ActiveSupport's core_ext. >> >> > The first one I wrote is groups-of (similar to ActiveSupport's >> > in_groups_of): >> >> > (defn groups-of >> > "Returns coll in groups of x size, optionally padding any remain

Re: groups-of

2008-12-19 Thread Rich Hickey
On Dec 19, 8:59 am, "Michael Wood" wrote: > On Fri, Dec 19, 2008 at 1:02 PM, hosia...@gmail.com > wrote: > > > I'm learning Clojure by trying to implement some functions from Ruby > > core/stdlib/ActiveSupport's core_ext. > > > The first on

Re: groups-of

2008-12-19 Thread Michael Wood
On Fri, Dec 19, 2008 at 1:02 PM, hosia...@gmail.com wrote: > > I'm learning Clojure by trying to implement some functions from Ruby > core/stdlib/ActiveSupport's core_ext. > > The first one I wrote is groups-of (similar to ActiveSupport's > in_groups_of): > &

groups-of

2008-12-19 Thread hosia...@gmail.com
I'm learning Clojure by trying to implement some functions from Ruby core/stdlib/ActiveSupport's core_ext. The first one I wrote is groups-of (similar to ActiveSupport's in_groups_of): (defn groups-of "Returns coll in groups of x size, optionally padding any remaining