kotools / libraries

Multiplatform libraries for expressive programming with Kotlin.
https://kotools.github.io/libraries
MIT License
0 stars 0 forks source link

`orThrow` and `orNull` builder variants #118

Closed LVMVRQUXL closed 1 year ago

LVMVRQUXL commented 1 year ago

Description

For all types, add builder variants suffixed with orThrow and orNull. Here's an example for NotBlankString, NonZeroInt and NotEmptyList types:

fun String.toNotBlankStringOrThrow(): NotBlankString = TODO()
fun String.toNotBlankStringOrNull(): NotBlankString? = TODO()

fun Int.toNonZeroIntOrThrow(): NonZeroInt = TODO()
fun Int.toNonZeroIntOrNull(): NonZeroInt? = TODO()

fun <E> Collection<E>.toNotEmptyListOrThrow(): NotEmptyList<E> = TODO()
fun <E> Collection<E>.toNotEmptyListOrNull(): NotEmptyList<E>? = TODO()

Checklist

LVMVRQUXL commented 1 year ago

These operations brings more complexity than value and can be replaced by the existing API of kotlin.Result.