-
Notifications
You must be signed in to change notification settings - Fork 55
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
Support for "Async" validation #56
Comments
I'm not sure this jives with Accord's fundamental design goals (see discussion on #53), but I'm not yet convinced one way or the other. A sensible baseline implementation would go a long way towards convincing me ;-) |
I am trying an implementation now, its not completely trivial (as that other issue is describing), but I will see how it goes. I am basically making an AsyncValidator/AyncResult types, and probably conversions/lifting (maybe implicit) from the standard types to the AsyncVersions |
+1 |
@dsounded @mdedetrich Can either of you provide a usage example? A case where this would be useful, and what your ideal syntax would look like? |
@holograph Simple example, let's say I want to implement my But needs boolean result, it will be ok if can wrap it in |
@holograph My use case is pretty much the same, its when you have validation that depends on a database (or HTTP service or something along these lines), basically anything that returns a I haven't had any time to get a working version, I made an attempt quite some time ago but didn't manage to get a working version (I had issues in making the various I think if this is to go forward we should probably have a look at how its going to be designed, since once you use the |
... which is why I'm not entirely clear on how the the whole thing should work. Returning a
To actually be able to make progress, I'd like some idea on what the definition API would look like if Futures are supported: trait FutureValidator[T] {
def apply(value: T)(implicit ec: ExecutionContext): Future[Result]
}
val aValidDBEntity: FutureValidator[String] = ???
val futurePersonValidator = futureValidator[Person] { p =>
p.name is notEmpty
p.address is valid
p.objectType is aValidDBEntity
} My concerns here are backwards-compatibility (I don't see how to work around having a |
I'll be honest I havn't really played much with accord, but as a Scala newbie, I "understand" modes much easier then canBuildFrom canBuildFrom seems like magic that I can ignore until I run into issues, propensives modes, as long as they are documented, make sense as it's I, the author, importing something which changes the behaviour. Whilst I don't really understand how either work, at least I feel like i'm in control when I'm using modes. |
Adding first class support for "Async" validation (i.e. through using
scala.concurrent.Future
) would enable you to do validation that involves looking up values from Databases or other services (i.e. you would be able to make a validation forUserId
which checks ifUserId
exists), in a performant non blocking way.scala.concurrent.Future
also exists on Scala.js, so this wouldn't effect Scala.js support.I suppose you would create an
asyncValidator
which requires something of typeFuture[T]
, and just like with normal validation, accord would handle transformations and chains of validations.One could argue that this could be out of scope for accord, however
scala.concurrent.Future
is part of stdlib, so it wouldn't add any dependencies.Would also be willing to make a pull request with the implementation assuming there are no major qualms with the idea
The text was updated successfully, but these errors were encountered: