I have seen an article <https://www.47deg.com/blog...
# arrow
n
I have seen an article https://www.47deg.com/blog/arrow-v0-10-3-release/ and really corious about one particular thing:
Either.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
Copy code
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
Copy code
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
Copy code
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.
k
That is an interesting question! I was thinking about the same the other day thanks for raising! I am curious about this
s
Iirc, every function that runs something that runs not as a 'pure' function, is marked as 'suspend'.
👌 1