Pueffl
10/12/2020, 2:27 PMval parallelValidate = Validated.applicativeNel<ConfigError>()
.tupledN(v1.toValidatedNel(), v2.toValidatedNel()).fix()
.map { (a, b) -> /* combine the result */}
This example works, but it works only for values that are not optional?, so the current implementation is rather useless as you will not have Forms with every field mandatory (or Object with only mandatory fields when you create an instance in map {...} after validating each field.
Should I consider this as a bug and report it or how would I validate a bunch of fields where some of them can be null?raulraja
10/12/2020, 2:54 PMPueffl
10/12/2020, 3:16 PMfun build(): Validated<NonEmptyList<Failure>, PwdAuthentication> {
val valId = nonNull(id, "id").flatMap { Id.create(it, "id") }
val valOwnerid = nonNull(ownerId, "ownerId").flatMap { Id.create(it, "ownerId") }
val valUsername = nonNull(username, "username").flatMap { NonBlankString.create(it, "username") }
val valPassword = nonNull(password, "password").flatMap { Password.create(it, "password") }
return Validated.applicativeNel<Failure>()
.tupledN(
Validated.fromEither(valId).toValidatedNel(),
Validated.fromEither(valOwnerid).toValidatedNel(),
Validated.fromEither(valUsername).toValidatedNel(),
Validated.fromEither(valPassword).toValidatedNel()
)
.fix()
.map { (id, ownerId, username, password) ->
PwdAuthentication(id, ownerId, username, password)}
}
This works fine but it would not if one of the fields (e.g. ownerId) of PwdAuthentication would be optional? and null for this validation. In that case, I can't use tupleN because there is no validation for ownerId. At the moment I'm trying to figure out how to solve this (all help appreciated :-)).
For me, the example in the docs is rather a special case which will work sometimes, but usually you will have values that are just null or not set and then this example is not very helpful. As an ordinary (and rather new) user I search for a pattern that works in any case and this pattern does not, so I wouldn't use it at all (but maybe I just miss something).Pueffl
10/12/2020, 3:25 PMjulian
10/12/2020, 3:44 PMPueffl
10/12/2020, 3:46 PMjulian
10/12/2020, 3:47 PMPueffl
10/12/2020, 4:00 PMjulian
10/12/2020, 5:44 PMraulraja
10/12/2020, 5:54 PMraulraja
10/12/2020, 5:55 PMstojan
10/12/2020, 6:22 PMraulraja
10/12/2020, 6:24 PMraulraja
10/12/2020, 6:24 PMPueffl
10/12/2020, 6:43 PMPueffl
10/13/2020, 4:28 PMjulian
10/13/2020, 4:33 PMPueffl
10/13/2020, 4:35 PMstojan
10/13/2020, 4:39 PMPueffl
10/13/2020, 4:46 PMstojan
10/13/2020, 4:56 PM