Thanks.  I hadn't thought of (apply > ...) - nice!

On Sunday, August 20, 2017 at 5:55:01 PM UTC-7, Ghadi Shayban wrote:
>
> You have the right idea with s/and.  I would name & defn the predicate to 
> something meaningful like increasing?.  Defining and thus naming it is 
> essential so that you can get reuse, and also so that consumers of your 
> spec, whether it's you or someone else, don't have to interpret the code in 
> the brain.  Btw, the impl can be simplified, but I still wouldn't inline it.
>
> (defn increasing? [coll]
>   (apply < coll))
> #'user/increasing?
> user=> (increasing? [1 2 3])
> true
> user=> (increasing? [1 2 2])
> false
> (s/and (s/coll-of number?) increasing?)
>
>
> On Sunday, August 20, 2017 at 7:53:48 PM UTC-4, Mark wrote:
>>
>> What's the 'right' way to spec relationship between values in a sequence? 
>>  For example, the following spec defines a sequence of number in increasing 
>> order:
>>>
>>>
>>>
>>> (s/conform (s/and (s/coll-of number?)
>>>                   #(->> %
>>>                         (partition 2 1)
>>>                         (map (fn [[a b]] (< a b)))
>>>                         (every? true?)))
>>>            [1 2 3])
>>>
>>> It feels like there ought to be a more elegant solution - especially as 
>> the relationships become more complex.  Is there another approach?
>>
>

-- 
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/d/optout.

Reply via email to