dashbitco / nimble_options

A tiny library for validating and documenting high-level options. 💽
Apache License 2.0
507 stars 38 forks source link

Add the {:value, expected} type #56

Closed whatyouhide closed 3 years ago

whatyouhide commented 3 years ago

This type is not particularly useful per se, but will be really handy for :or. For example, nimble_option's :doc can be validated as:

[
  doc: [type: {:or, [{:value, false}, :string]}]
]

Thoughts?

wojtekmach commented 3 years ago

+1 from me, I think another good use case is re-implementing timeout:

[
  timeout: [type: {:or, [{:value, :infinity}, :non_neg_integer]}]
]
josevalim commented 3 years ago

Isn't this the same as {:in, [false]}? 🤔 Maybe keep in and improve the error message if it has only one element?

whatyouhide commented 3 years ago

@josevalim that is a Good Point™, didn't think about it! I won't even improve the error message for now, it's fine 😄