mirror of
https://github.com/Shabinder/SpotiFlyer.git
synced 2024-11-26 02:24:31 +01:00
Fixes
This commit is contained in:
parent
8d5e9cdccc
commit
7da3147b69
@ -8,9 +8,9 @@ inline fun <reified X> SuspendableEvent<*, *>.getAs() = when (this) {
|
|||||||
is SuspendableEvent.Failure -> error as? X
|
is SuspendableEvent.Failure -> error as? X
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend inline fun <V : Any?> SuspendableEvent<V, *>.success(crossinline f: suspend (V) -> Unit) = fold(f, {})
|
suspend inline fun <V : Any?> SuspendableEvent<V, *>.success(noinline f: suspend (V) -> Unit) = fold(f, {})
|
||||||
|
|
||||||
suspend inline fun <E : Throwable> SuspendableEvent<*, E>.failure(crossinline f: suspend (E) -> Unit) = fold({}, f)
|
suspend inline fun <E : Throwable> SuspendableEvent<*, E>.failure(noinline f: suspend (E) -> Unit) = fold({}, f)
|
||||||
|
|
||||||
infix fun <V : Any?, E : Throwable> SuspendableEvent<V, E>.or(fallback: V) = when (this) {
|
infix fun <V : Any?, E : Throwable> SuspendableEvent<V, E>.or(fallback: V) = when (this) {
|
||||||
is SuspendableEvent.Success -> this
|
is SuspendableEvent.Success -> this
|
||||||
@ -105,7 +105,7 @@ sealed class SuspendableEvent<out V : Any?, out E : Throwable>: ReadOnlyProperty
|
|||||||
abstract operator fun component1(): V?
|
abstract operator fun component1(): V?
|
||||||
abstract operator fun component2(): E?
|
abstract operator fun component2(): E?
|
||||||
|
|
||||||
suspend inline fun <X> fold(crossinline success: suspend (V) -> X, crossinline failure: suspend (E) -> X): X {
|
suspend inline fun <X> fold(noinline success: suspend (V) -> X, noinline failure: suspend (E) -> X): X {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is Success -> success(this.value)
|
is Success -> success(this.value)
|
||||||
is Failure -> failure(this.error)
|
is Failure -> failure(this.error)
|
||||||
@ -164,11 +164,9 @@ sealed class SuspendableEvent<out V : Any?, out E : Throwable>: ReadOnlyProperty
|
|||||||
Failure(ex as E)
|
Failure(ex as E)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend inline operator fun <V : Any?> invoke(crossinline block: suspend () -> V): SuspendableEvent<V, Throwable> = try {
|
suspend inline operator fun <V : Any?> invoke(
|
||||||
Success(block())
|
crossinline block: suspend () -> V
|
||||||
} catch (ex: Throwable) {
|
): SuspendableEvent<V, Throwable> = of(block)
|
||||||
Failure(ex)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -17,7 +17,6 @@
|
|||||||
package com.shabinder.common.di.providers
|
package com.shabinder.common.di.providers
|
||||||
|
|
||||||
import co.touchlab.kermit.Kermit
|
import co.touchlab.kermit.Kermit
|
||||||
import com.shabinder.common.di.audioToMp3.AudioToMp3
|
|
||||||
import com.shabinder.common.di.youtubeMp3.Yt1sMp3
|
import com.shabinder.common.di.youtubeMp3.Yt1sMp3
|
||||||
import com.shabinder.common.models.corsApi
|
import com.shabinder.common.models.corsApi
|
||||||
import com.shabinder.common.models.event.coroutines.SuspendableEvent
|
import com.shabinder.common.models.event.coroutines.SuspendableEvent
|
||||||
@ -30,9 +29,9 @@ interface YoutubeMp3: Yt1sMp3 {
|
|||||||
operator fun invoke(
|
operator fun invoke(
|
||||||
client: HttpClient,
|
client: HttpClient,
|
||||||
logger: Kermit
|
logger: Kermit
|
||||||
): AudioToMp3 {
|
): YoutubeMp3 {
|
||||||
return object : AudioToMp3 {
|
return object : YoutubeMp3 {
|
||||||
override val client: HttpClient = client
|
override val httpClient: HttpClient = client
|
||||||
override val logger: Kermit = logger
|
override val logger: Kermit = logger
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user