I am trying to remove the `IO` and `ObservableK` f...
# arrow
k
I am trying to remove the
IO
and
ObservableK
from my library module and standardize calls around
F
using
Concurrent<F>
. Arrow version
0.11.0-SNAPSHOT
usage of
fx
mentions that
fx: MonadFx<F>' is deprecated. Overrides deprecated member in ‘arrow.typeclasses.MonadError’. Fx will be moved to each datatype as a DSL constructor.
What would be the correct usage for fx in this case?
example:
Copy code
override fun getShowImage(id: Int): IO<ShowImageResponse> =
    tmdbService.getShowImage(id)
      .defer(IO.async())
      .flatMap { it.unwrapBody(IO.applicativeError()) }

  override fun getShowImageStream(id: Int): ObservableK<ShowImageResponse> =
    tmdbService.getShowImage(id)
      .defer(ObservableK.async())
      .flatMap { it.unwrapBody(ObservableK.applicativeError()) }
Moving the separate implementation into:
Copy code
fun <F> Concurrent<F>.getShowImage(id: Int): Kind<F, ShowImageResponse> =
      tmdbService.getShowImage(id).async(fx.M)
        .flatMap { it.unwrapBody(fx.M) }
With Concurrent<F> the fx is deprecated, and not sure how to get the Async<F> and ApplicativeError any other way 🤔
s
Hey @kioba, We're in the process of removing
fx
in favor of computational blocks, and replacing
F
for continuations completely. This looks however something that I'd implement over
Fx
and instead using
MonadDefer
we'll introduce integration packages such as can be found in KotlinX Coroutines to properly integrate
cancellation
.
Copy code
fun observableEffect(f: suspend () -> A): Observable<A>
This will also result in a more straight-forward API since the typeclasses were never really properly prepared for streaming.
I'm however not 100% sure here what you're trying to do with
fx
, it seems you're trying to get hold of a typeclass instance but it's not letting you? 🤔
k
it seems you’re trying to get hold of a typeclass instance but it’s not letting you? 🤔
Yes, that is correct. I am using
fx
to reach the TypeClasses of
F
higher kinded type.
s
Okay, in that case you should be able to pass
Concurrent
as
Async
, since
interface Concurrent<F> : Async<F>
which through
Bracket
also extend
MonadDefer
.
👍 1
k
If I understand correctly,
suspend () -> A
and
Kind<F, A>
is the same and the suspend function could replace
F
s
Yes, that's correct!
suspend
is however a cheaper encoding, and will allows us to get rid of
Kind
etc without having to rely on compiler plugins.
It's know as delimited continuations, which is also a part of Project Loom. And they've even build an Effekt language on top. Which is also where we're drawing inspiration from, but distilling it into a Kotlin idiomatic jacket. https://effekt-lang.org/
❤️ 1
k
ohh wow, that is really nice. Takes a while to get used to the concept 😅 . Does that mean the Typeclasses are out of the vision? Or just pass them as recievers?
suspend Functor<F>.myfunction() : A
s
Not all typeclasses are out of the vision, but the monad hierarchy will most likely become completely redundant. Which are all used for control flow, which is what can also be implemented using
Continuation
. Computation typeclasses such as Monoid, Align, etc will all still be relevant since those don't abstract over control flow but over logic/computations.
👍 1