We're migrating from funktionale to arrow. I couldn't find a reference to the arrow-validation module in issues or pull requests. It seems that its maven artifact isn't being deployed along the rest, as it is missing the following gradle apply (found in other modules):
apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
As there is no mention of this module in the readme, I'm guessing this is intentional. Maybe it's not ready for prime time, or maybe we should find a replacement in other modules. Any feedback is appreciated, we'll continue reading the docs 馃槃
That was an oversight, on the other hand the library is so underused that this is the first time someone has noticed lol We'll fix it for next release.
My suggestion regardless is to migrate over to the Validated datatype and Validated.applicative()#map to construct new values.
https://arrow-kt.io/docs/datatypes/validated/
https://arrow-kt.io/docs/typeclasses/applicative/#applicative-builder-examples
Thank you for the pointers! I looked into the links, and once I wrapped my head around semigroups, I think I got it.
So, if I understood it correclty
Validated is kinda like a new and improved DisjunctionEither filled that hole, but at least from the perspective of arrow-validation, which previously used it as a sort of valid/invalid objectValidated.applicative() requires a semigroup to which it can "combine" the invalid values it encounters during map()Validated and the applicative map(), I need to call fix() for... type reasonsOr, in as small Kotlin file I could muster (adapts the video's example here):
package foobar
import arrow.data.*
import org.junit.jupiter.api.Test
import java.util.*
typealias KnownErrors = NonEmptyList<ValidatedTest.KnownError>
class ValidatedTest {
object KnownError
data class Person(val id: UUID, val name: String, val year: Int)
fun <T> validatedData(t: T? = null) = t
?.let { Valid(t) }
?: Invalid(NonEmptyList.just(KnownError))
fun printData(
label: String,
vId: Validated<KnownErrors, UUID>,
vName: Validated<KnownErrors, String>,
vAge: Validated<KnownErrors, Int>) {
Validated
.applicative(NonEmptyList.semigroup<KnownError>())
.map(vId, vName, vAge) { (id, name, age) ->
Person(id, name, age)
}
.fix()
.fold({
println("$label Errors: $it")
}, {
println("$label Valid: $it")
})
}
@Test
fun test() {
printData(
"allValid",
validatedData(UUID.randomUUID()),
validatedData("William"),
validatedData(1926)
)
printData(
"someValid",
validatedData(null),
validatedData(null),
validatedData(1926)
)
}
}
I think I understand this now. At least enough to carry the migration work. Thanks again!
Should this issue be closed, or do you wish to retain it to track the inclusion of arrow-validation?
I'll keep the issue open, if you don't mind me changing the title to be more task-oriented.
I don't mind at all! Thanks again 馃憤
Most helpful comment
Thank you for the pointers! I looked into the links, and once I wrapped my head around semigroups, I think I got it.
So, if I understood it correclty
Validatedis kinda like a new and improvedDisjunctionEitherfilled that hole, but at least from the perspective ofarrow-validation, which previously used it as a sort of valid/invalid objectValidated.applicative()requires a semigroup to which it can "combine" the invalid values it encounters duringmap()Validatedand the applicativemap(), I need to callfix()for... type reasonsOr, in as small Kotlin file I could muster (adapts the video's example here):
I think I understand this now. At least enough to carry the migration work. Thanks again!
Should this issue be closed, or do you wish to retain it to track the inclusion of
arrow-validation?