https://kotlinlang.org logo
#arrow
Title
# arrow
h

HieiJ

05/21/2019, 7:07 PM
Hi all! Some days ago we were talking here about
suspend
functions that, in Arrow Fx, could be defined "pure" as their side effects are suspended until the "end of the world". But I was wondering about referential transparency of this kind of functions; I concluded that
suspend
functions are referentially transparent only when wrapped inside an
effect {}
block; instead, when a
suspend
function is called from another
suspend
function, it isn't. An example is the following:
Copy code
suspend fun readNumberFromConsole(): Int = TODO("Side effect that returns an integer")

suspend fun example1(): Int {
    val x = readNumberFromConsole()
    return x + x;
}

suspend fun example2(): Int {
    return readNumberFromConsole() + readNumberFromConsole()
}
What do you think about this? Could this be a bit misleading when writing functional code?
2 Views