Variant KOptional

This commit is contained in:
DBotThePony 2024-03-09 17:35:52 +07:00
parent e189009494
commit ed1840a315
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 5 additions and 5 deletions

View File

@ -4,7 +4,7 @@ kotlin.code.style=official
specifyKotlinAsDependency=false specifyKotlinAsDependency=false
projectGroup=ru.dbotthepony.kommons projectGroup=ru.dbotthepony.kommons
projectVersion=2.9.17 projectVersion=2.9.18
guavaDepVersion=33.0.0 guavaDepVersion=33.0.0
gsonDepVersion=2.8.9 gsonDepVersion=2.8.9

View File

@ -59,7 +59,7 @@ class KOptional<T> private constructor(private val _value: T, val isPresent: Boo
} }
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun orElse(value: T): T { inline fun <E : T> orElse(value: E): T {
if (isPresent) { if (isPresent) {
return this.value return this.value
} else { } else {
@ -67,7 +67,7 @@ class KOptional<T> private constructor(private val _value: T, val isPresent: Boo
} }
} }
inline fun orElse(value: () -> T): T { inline fun <E : T> orElse(value: () -> E): T {
if (isPresent) { if (isPresent) {
return this.value return this.value
} else { } else {
@ -75,11 +75,11 @@ class KOptional<T> private constructor(private val _value: T, val isPresent: Boo
} }
} }
infix fun or(value: KOptional<T>): KOptional<T> { infix fun <E : T> or(value: KOptional<E>): KOptional<T> {
if (isPresent) { if (isPresent) {
return this return this
} else { } else {
return value return value as KOptional<T>
} }
} }