Last active
January 3, 2021 14:40
-
-
Save lucapiccinelli/9064ab3f88dad5f7275c143e7dcfc689 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
import io.konad.Result | |
inline class NotEmptyString | |
@Deprecated(level = DeprecationLevel.ERROR, message = "use companion method 'of'") | |
constructor(val value: String){ | |
companion object{ | |
@Suppress("DEPRECATION_ERROR") | |
fun of(value: String): Result<NotEmptyString> = valikate { | |
validate(NotEmptyString(value)){ | |
validate(NotEmptyString::value).isNotBlank() | |
} | |
} | |
} | |
} | |
internal inline fun <reified T> valikate(valikateFn: () -> T): Result<T> = try{ | |
valikateFn().ok() | |
}catch (ex: ConstraintViolationException){ | |
ex.constraintViolations | |
.mapToMessage() | |
.joinToString("\n") { "\t\"${it.value}\" of ${T::class.simpleName}.${it.property}: ${it.message}" } | |
.error() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment