commonMain.target.core.ValueValidator.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of target-core-jvm Show documentation
Show all versions of target-core-jvm Show documentation
Functional domain modeling in Kotlin
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) }
}