I am trying to use arrow in kotlin
Arrow has three functions
IO {}
IO.fx {}
IO.fx { !effect}
I want to know the difference between these. I know IO.fx and IO.fx {!effect} help us use side effects but then whats the difference between the two and why would I use one over the other
While this is going to change shortly, on version 0.11.X:
IO { }is a constructor that takes a suspend function, so you can call any suspend function inside. It's a shortcut forIO.effect { }IO.fx { }is the same asIOexcept it adds a few DSL functions that are shortcuts for other APIs of IO. The most important one is!orbind, which executes another IO inside.Another function it enables is the constructor
effectfrom the first point. So what you're effectively doing is adding an additional layer of wrapping that may not be necessary.We frequently see that
inefficientUnpackedIOfrom people who come to the support channels, and it's easily replaceable by justIO { bla() }.Why have two ways of doing the same in
effectandfx? It's something we're looking to improve on the next releases. We recommend using the least powerful abstraction wherever possible, so reservefxonly when using otherIO-based APIs such as scheduling or parallelization.