Nikita Smolenskii
11/15/2019, 9:28 AMEither.catch
that forces suspend.
Article provides following code snippet, that somehow correate with current implementation https://github.com/arrow-kt/arrow/blob/b332574a969497dc9f072d52bbb5eea60081a9fe/modules/core/arrow-core-data/src/main/kotlin/arrow/core/Either.kt#L859
suspend fun <A> Either.Companion.catch(f: suspend () -> A): Either<Throwable, A> =
try { f().right() } catch (t: Throwable) { t.left() }
Is there any particular reason to not do instead, that allow catch
function to be suspend
agnostic
inline fun <A> Either.Companion.catch(f: () -> A): Either<Throwable, A> =
try { f().right() } catch (t: Throwable) { t.left() }
with that decalration, both will be possible, with initial declaration - second one only
fun blocking(): Int = 42
suspend fun suspended(): Int = 42
fun main() {
Either.catch { "first: ${blocking()}" }
runBlocking {
Either.catch { "second: ${suspended()}" }
}
}
Why arrow team forces to use coroutines everywhere? Even if it’s not needed.kioba
11/15/2019, 12:17 PMstreetsofboston
11/15/2019, 1:12 PM