arrow icon indicating copy to clipboard operation
arrow copied to clipboard

IO Monad deprecation - Ergonomics section

Open modernptz opened this issue 2 years ago • 4 comments

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.

modernptz avatar Oct 23 '21 22:10 modernptz

The example may not be great, as it assumes that it requires sequentiality but the code doesn't reflect it.

pakoito avatar Oct 24 '21 12:10 pakoito

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.

modernptz avatar Oct 24 '21 16:10 modernptz

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.

pakoito avatar Oct 24 '21 20:10 pakoito

@modernptz @pakoito are you OK with closing this issue? I think it's a long time since Arrow migrated from IO to suspend functions.

serras avatar Aug 09 '22 13:08 serras