New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for PartialRangeUpTo in validators #2369
Conversation
…ators This also improves and fixes documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!!
A couple nits ('cause it wouldn't be me if I didn't 🙂):
-
Unless I missed them (very possible!), there don't seem to be any tests for
PartialRangeFrom
, can you add a couple? -
Could you add a more-generic overload for accepting any
RangeExpression
not already covered by the specializations?-
For the
count()
validators, something likepublic static func count<R: RangeExpression>(_ range: R) where R.Bound == Int { .count(range.relative(to: .zero ... .max)) }
(give or take a generic constraint maybe). -
For the
range()
validators, it'd go in a new extension that requiresT: Comparable & FixedWidthInteger
conformance, bewhere R.Bound == T
, and look something like.range(range.relative(to: .min ... .max))
, I think.
-
These are completely optional, though; the PR is already great as-is! ❤️
@gwynne Thanks for the review! 🙂
I didn't know about this protocol, unfortunately it seems like you can't use a range with |
Done! 🙂 |
Nah, don't worry about it - the primary utility of I'm happy with this as it now stands. Ping @tanner0101 to give it a glance before it gets merged. |
@gwynne I saw your comment too late 😃 I can still remove it if that's better without it |
@adtrevor I like what you did to implement that! But yeah, I think we're better off without it conceptually as well as for simplicity. Once you revert the commits to add the |
1878afb
to
c23d40a
Compare
@gwynne No problem! 🙂 Reverted! |
These changes are now available in 4.8.0 |
Up until right now, the
.count(...)
and.range(...)
validators didn't support being passed aPartialRangeUpTo
. This commit adds support for this.This also improves and fixes documentation