Last active
January 9, 2021 08:11
-
-
Save lucapiccinelli/697b1f3a1ae10b09eb88728f4557fb01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class PersonalName( | |
val firstname: NotEmptyString, | |
val middleInitial: NotEmptyString?, | |
val lastname: NotEmptyString){ | |
companion object { | |
fun of(firstname: String, lastname: String, middleInitial: String? = null): Result<PersonalName> = | |
::PersonalName.curry() | |
.on(NotEmptyString.of(firstname)) | |
.on(middleInitial?.run { NotEmptyString.of(middleInitial) } ?: null.ok()) | |
.on(NotEmptyString.of(lastname)) | |
.result | |
} | |
} | |
when(val nameResult = PersonalName.of("Foo", "", "")){ | |
is Result.Ok -> nameResult.value.toString() | |
is Result.Errors -> nameResult.description("\n") | |
}.run(::println) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment