Closed fran-worley closed 8 years ago
Yes it is, you're not the first person who asked for it. IIRC we thought about naming it contains?
but I'd be ok with includes?
and excludes?
although there's a risk people will be confused with inclusion?
vs includes?
- but I gotta say I never ever liked inclusion?
, we picked it up because people are familiar with it. Blah
I thought of contains but what do you do for the opposite? I wasn't happy with anything I came up with (does_not_contain, missing, absent, lacks).
You could do:
input.includes?(value)
input.included_in?(list) #instead of inclusion
input.excludes?(value)
input.excluded_from?(list) #instead of exclusion
We could always create aliases for inclusion and exclusion for backwards compatibility.
Or (might be a bit much magic) you could determine what to call .include?
on based on the type of argument supplied similar to how the Size predicate works.
Actually, that isn't a good idea please ignore!!
I like your suggestion, @fran-worley:
input.includes?(value)
input.included_in?(list) #instead of inclusion
input.excludes?(value)
input.excluded_from?(list) #instead of exclusion
It looks a lot clearer to me, and it seems @solnic isn't attached to the current naming. Now might also be a good time to get it in, given we're changing the basic DSL anyway.
Would you be up for making this change (and deprecating the other names) along with https://github.com/dry-rb/dry-logic/pull/9?
Yup will do. I'll also PR dry-v and the docs to update .
closed via #9
The current inclusion and exclusion predicates take a list and check that the input is included in that list.
I have just run into a use case where I want to turn this on its head and instead check that the input includes a value.
Does this seem like something worth adding to the library?
In terms of names I guess we either go for
:includes?
and:excludes?
the idea being that we are checking if an input includes or excludes something. However they might be a little similar to the current predicates...