-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d07bd58
commit 6a5523c
Showing
4 changed files
with
30 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
18 changes: 0 additions & 18 deletions
18
example/src/main/kotlin/com/github/michaelbull/result/example/model/domain/PersonalName.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,6 @@ | ||
package com.github.michaelbull.result.example.model.domain | ||
|
||
import com.github.michaelbull.result.Err | ||
import com.github.michaelbull.result.Ok | ||
import com.github.michaelbull.result.Result | ||
|
||
data class PersonalName( | ||
val first: String, | ||
val last: String | ||
) | ||
|
||
private const val MAX_LENGTH = 10 | ||
|
||
fun Pair<String?, String?>.toPersonalName(): Result<PersonalName, DomainMessage> { | ||
val (first, last) = this | ||
|
||
return when { | ||
first.isNullOrBlank() -> Err(FirstNameRequired) | ||
last.isNullOrBlank() -> Err(LastNameRequired) | ||
first.length > MAX_LENGTH -> Err(FirstNameTooLong) | ||
last.length > MAX_LENGTH -> Err(LastNameTooLong) | ||
else -> Ok(PersonalName(first, last)) | ||
} | ||
} |