Fork me on GitHub
#clojure-spec
<
2017-11-17
>
otfrom08:11:54

when writing the :fn bit of an fdef, doesn anyone have any tips or examples to figure out which bit of the fn failed if there are multiple properties that should hold?

otfrom08:11:41

or with labels almost gives what I want, but obviously isn't logically correct. I want something like all

tcoupland08:11:16

something abit like:

(s/all [{{:keys [first]} :args second :ret}]
           :value-mismatch #(= (:value first)
                                        (:value second)))
would be very tidy for checking a value was copied correctly in the function

triss10:11:17

is there a way to write a spec that says: a collection containing two or more integers and anything else?

gklijs10:11:03

would became something like, and it would need to be a collection, and when filtered on number? the size is minimal of 2

tcoupland11:11:43

@triss sounds like an s/cat which makes use of some of the regexp elements

Olical12:11:20

Does anyone know if you can spec a map and have it conformed into multiple parts depending on the key. For example, conform {:A 1 :B 2 :a 1 :b 2} into something like {:upper {:A 1 :B2} :lower {...}}. Basically a group-by during a conform.

Olical12:11:54

I essentially want different rules for different kinds of keys in a map. So certain styles of keys would have different value requirements.

andre.stylianos12:11:51

From what I've been seeing of the usage of spec, I'd guess not. Seems like it falls under the "data transformation" camp which is not something they intend spec to be used for.

andre.stylianos12:11:20

but I might be wrong

Olical12:11:35

Yep, that's how I was beginning to feel about it. I'm currently doing that transformation after the fact, but it's hard to find them in a recursive spec, so I can't do the transform up front ahead of time.

Olical12:11:43

I don't want to walk the tree multiple times is all.

Olical12:11:09

I would quite like different specs for different kinds of keys though, not sure if I can do that.

Olical12:11:36

In my case, if it starts with on- I want it to be restricted to a function value. If it's anything else it should be a string.

andre.stylianos12:11:29

makes sense. Does it have to be a tree? You could {:upper/A 1 :upper/B 2 :lower/a 1...}

andre.stylianos12:11:33

and not quite sure what you mean by "different specs for different kinds of keys though, not sure if I can do that."

Olical12:11:07

Yup, I'm not sure either 🙂 It's like, I don't care about the actual keys, as long as they're keywords. But if it starts with on- it should be a function. I wonder if I can combine map-of and keys. It's almost like I want two stages, conform as much as you can with this spec, THEN conform with this spec.

Olical12:11:33

Right now I'm just doing map-of keywords to string or function.

Olical12:11:10

I just need constraints between key and value. Otherwise if I exercised this spec it would generate invalid runtime data, but it would match the spec.

andre.stylianos12:11:55

Yeah, for what you're saying it seems like map-of would be a fitting choice

andre.stylianos12:11:41

But I'm not sure if there's a way to treat the key/value pair as a whole with map-of

Olical12:11:04

I think I need a hybrid that doesn't exist 😅

andre.stylianos12:11:18

Another option might be coll-of if map-of doesn't work, since that way you could probably spec each entry as [k v] pairs

Olical12:11:01

For context, this is an attribute map that will be applied to DOM nodes in this little Reagent/React like thing I'm building.

Olical12:11:30

So most keys will just be strings that go to setAttribute on a DOM node, but event listeners are special things that are handled separately.

Olical12:11:50

I'm using spec as a parser of my hiccup like data structure basically.

Olical12:11:32

People with the same issue, linking back to this Slack.

Olical12:11:42

Found a strange loop 😄

Olical12:11:25

Alex to the rescue.

otfrom14:11:06

anyone out there have good examples of complex fn's on a :fn for a fdef?

otfrom14:11:19

(esp ones that do good reporting of what bit of the fn has failed)