dashbitco / nimble_options

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

Member type #15

Closed whatyouhide closed 4 years ago

whatyouhide commented 4 years ago

A pretty common possible option value is a member of a list. An example that comes to mind is Broadway's :batch_mode in Broadway.test_messages/3, which is :bulk or :flush.

Do we want to support a "member" type?

schema = [
  batch_mode: [type: {:member, [:bulk, :flush]}, default: :flush]
]

Do you think it's too soon, too specific, or a good addition?

josevalim commented 4 years ago

Sounds good to me but I think :one_of would be a better name?

whatyouhide commented 4 years ago

@josevalim I wanted to keep one_of for the possibility of compound types later on (such as {:one_of, [:integer, :string, :atom]}. Thoughts?

josevalim commented 4 years ago

@whatyouhide I would say that is a :union. :)

whatyouhide commented 4 years ago

@josevalim fair enough, I'll make a PR for :one_of then.

wojtekmach commented 4 years ago

I like this proposal. Should this support a list or more generally any enumerable?

Btw, when I was evaluating libraries like Saul and Norm I arrived at the following list of operations that seemed useful

:symmetric_difference doesn't quite has the same ring to it as the other two but it is by far less common :)

josevalim commented 4 years ago

In our case, since we don’t generate, I think only one_of is possible?

whatyouhide commented 4 years ago

This brings up the reason why I wanted to call it :member. Membership is about: is this value in this list (or set potentially)? The elements of the list are simple elements, not other validators. It's easy to implement and use. Thoughts?

josevalim commented 4 years ago

I would use one_of for values and union/intersection for types. Member sounds weird for some reason. ::