Skip to content
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

Publish arrow-validation to maven #914

Closed
Northburns opened this issue Jun 28, 2018 · 4 comments
Closed

Publish arrow-validation to maven #914

Northburns opened this issue Jun 28, 2018 · 4 comments

Comments

@Northburns
Copy link

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 😄

@pakoito
Copy link
Member

pakoito commented Jun 28, 2018

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

@Northburns
Copy link
Author

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?

@pakoito
Copy link
Member

pakoito commented Jun 28, 2018

I'll keep the issue open, if you don't mind me changing the title to be more task-oriented.

@Northburns
Copy link
Author

I don't mind at all! Thanks again 👍

@pakoito pakoito changed the title Status of arrow-validation Publish arrow-validation to maven Jun 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants