Is your feature request related to a problem? Please describe.
I want to be able to provide a custom type where a coercion is applied. In my case, I have a set that is too large to be worth printing to the screen.
Describe the solution you'd like
I would like an API where I can define functions that allows me to validate data, coerce data, and report errors to the user about what went wrong. If this exists, I did not see it in the docs.
For example:
{:type {;; validate returns `nil` on success and `str` on failure
:validate (fn [x] (if (= (% x 2) 0) "No even values"))
;; coerce must always succeed (no error/exception)
:coerce some-func-here}}
Or combine them into something (perhaps?) simpler.
{:type (fn [x] (if (= (% x 2) 0)
(throw (Exception. "No even values"))
(some-func-here x))}
Describe alternatives you've considered
I can do all this boilerplate in my code, but if it's a global option, I have to do it with all subcommands. I would rather define these functions in one place and know that the option that's being passed to my function has the correct type/value.
I also attempted using :type (fn [x] x) to test if it accepts functions, and it does not (though this is clear after inspecting the code).
Is your feature request related to a problem? Please describe. I want to be able to provide a custom type where a coercion is applied. In my case, I have a
set
that is too large to be worth printing to the screen.Describe the solution you'd like I would like an API where I can define functions that allows me to validate data, coerce data, and report errors to the user about what went wrong. If this exists, I did not see it in the docs.
For example:
Or combine them into something (perhaps?) simpler.
Describe alternatives you've considered I can do all this boilerplate in my code, but if it's a global option, I have to do it with all subcommands. I would rather define these functions in one place and know that the option that's being passed to my function has the correct type/value.
I also attempted using
:type (fn [x] x)
to test if it accepts functions, and it does not (though this is clear after inspecting the code).