arrow
arrow copied to clipboard
IO Monad deprecation - Ergonomics section
https://arrow-kt.io/docs/effects/io/ Not sure that ergonomics section has been written correctly, but since IO monad is Semigroup it should be possible to write something like that:
val number = IO.just(1)
val triple: IO<Triple> = (number,number,number).mapN(Triple(it))
So there is no need of flatMap.
However it's not exact code, just translation from cats to imaginable arrow.
The example may not be great, as it assumes that it requires sequentiality but the code doesn't reflect it.
Hm, to be honest when I see code like
Triple(number1(), number2(), number3())
I'm assuming that all this numbers should be run in parallel, not sequentially. There is no dependencies between 3 of this numbers.
Another thing is that you assuming that the suspend
is much more faster than IO
, but from talks of Roman Elizarov I know that all that compiler do it's translate suspend fun
code to java function with callback. So because of that the difference in speed of coroutine and well designed IO should not be dramatic, because the maximal overhead it's just spawning of IO class. Not sure if I'm right, but would be nice to have some benchmarks in that article.
We've been all the way and back over 4 years and yes, raw suspend
is significantly faster than any IO encoding in Kotlin or Scala. "to java function with callback" is an oversimplification for the sake of the talk, it does something completely different that behaves as such.
@modernptz @pakoito are you OK with closing this issue? I think it's a long time since Arrow migrated from IO
to suspend
functions.