Arrow: Publish arrow-validation to maven

Created on 28 Jun 2018  路  4Comments  路  Source: arrow-kt/arrow

https://github.com/arrow-kt/arrow/blob/884ad98a9a33130f9a1998bfa1663e15e93c733b/modules/core/arrow-validation/build.gradle#L14

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 馃槃

help wanted

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

  • Validated is kinda like a new and improved Disjunction

    • well, Either filled that hole, but at least from the perspective of arrow-validation, which previously used it as a sort of valid/invalid object

  • Validated.applicative() requires a semigroup to which it can "combine" the invalid values it encounters during map()
  • With Validated and the applicative map(), I need to call fix() for... type reasons

Or, 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?

All 4 comments

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 Disjunction

    • well, Either filled that hole, but at least from the perspective of arrow-validation, which previously used it as a sort of valid/invalid object

  • Validated.applicative() requires a semigroup to which it can "combine" the invalid values it encounters during map()
  • With Validated and the applicative map(), I need to call fix() for... type reasons

Or, 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 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

raulraja picture raulraja  路  5Comments

pakoito picture pakoito  路  4Comments

JorgeCastilloPrz picture JorgeCastilloPrz  路  3Comments

raulraja picture raulraja  路  4Comments

lgtout picture lgtout  路  4Comments