All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.target.core.ValueValidator.kt Maven / Gradle / Ivy

There is a newer version: 0.5.0
Show newest version
package target.core

import arrow.core.Either
import arrow.core.Either.Right
import arrow.core.None
import arrow.core.Option
import arrow.core.Some

interface ValueValidator, T : ValueObject> {

    fun of(input: I): Either

    fun ofNullable(input: I?): Either = input?.let(::of) ?: Right(null)

    fun of(input: Option): Either> = input.fold({ Right(None) }) { of(it).map(::Some) }

    fun ofNullable(input: Option): Either> =
        input.fold({ Right(None) }) { ofNullable(it).map(::Some) }
}