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

Stylianos Gakis

02/01/2023, 3:50 PM
In the docs of the
shift
function, a code snippet is attached:
Copy code
suspend fun main() {
  effect<String, Int> {
    shift("SHIFT ME")
  }.fold({ it shouldBe "SHIFT ME" }, { fail("Computation never finishes") })
}
Here shift knows what
B
(the return type) is due to it being the last in the function so it’s
Int
. When shift isn’t used at the end like that, one would need to explicitly pass something to be able to call shift, otherwise it won’t know what
B
is. How is this typically supposed to be used? Is explicitly passing a type there the expected approach while calling that function? And in reality, if I am only calling shift to short-circuit, I won’t use the return value, so should it just be
Unit
? For now I realized doing just
ensure(condition) { LeftType }
was what I wanted, but how about other cases?
r

raulraja

02/01/2023, 3:52 PM
shift is getting renamed to
raise
in 2.0 and the return type is no longer a generic
<A>
representing the exit but just
Nothing
This means that in the future
raise
only cares about the left type of the effect. If you don't ascribe the type in the effect it won't be able to infer Int in the right same as your example. I think the issue would still be the same but raise no longer depends on it. Here the issue is none of your function return an Int because they all exit with failures or shift
s

Stylianos Gakis

02/01/2023, 4:01 PM
Right, I knew I must’ve missed some discussion about this, thanks a lot for the clarification, this makes a lot of sense yeah! And this example was simply from the shift docs, hence I linked it here as an example. In my particular case I had the Right response down lower, but it’s as you described still a problem. The 2.0 syntax would fit exactly what I was going for 😎
12 Views