Variant KOptional
This commit is contained in:
parent
e189009494
commit
ed1840a315
@ -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
|
||||||
|
@ -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>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user