catch-data icon indicating copy to clipboard operation
catch-data copied to clipboard

Add map as catch-data predicate

Open kevbuchanan opened this issue 10 years ago • 4 comments

I've found myself wanting to catch based on values of domain specific keys in the exception data. You could do #(= :some-key (:some-value %)) as the predicate, but that seemed to get a bit repetitive. This use case, or the implementation, might not make sense to add, but just thought I'd propose it.

kevbuchanan avatar Mar 19 '15 17:03 kevbuchanan

I definitely appreciate the need, and I'd like to have some way of doing this. I'm a bit hesitant about map literals because they are technically functions so they would currently act as a predicate in that respect. I doubt backwards compatibility would be a real issue but confusing semantics might be.

Another option is a different clause name, but I don't know of a good one (catch-data-matching-map? :disappointed:)

I'll be giving this some thought. Thanks for the PR.

gfredericks avatar Mar 19 '15 19:03 gfredericks

Yeah, that all makes sense. I'd be happy to make some changes if you decide on a preferred way of doing something similar.

kevbuchanan avatar Mar 19 '15 19:03 kevbuchanan

Another idea: if you had a helper function that let you do (map-kv-pred :some-key :some-value), would that address most of your concerns? It's not as succinct as a map but there's at least fewer elements in the code, less nesting, etc.

If you do like that idea, the question would be if it belongs in this library (it's not directly related to exceptions, but seems unlikely to be too useful elsewhere), and if so what to call it.

gfredericks avatar Mar 20 '15 00:03 gfredericks

I like that idea. I called it sub-data. It could definitely be part of another library, or just implemented wherever it's needed - given that it's pretty simple - if you don't think it belongs here.

kevbuchanan avatar Mar 20 '15 20:03 kevbuchanan