If people are interested in starting `arrow-androi...
# arrow
s
If people are interested in starting
arrow-android
we’d love to help people get started with any help they need 🙂
👍 9
d
Do you have some use case in mind?
s
A great first step would be an integration between
IO
and the Android’s Lifecycle I think. Which we should be able to easily refactor to
F
later on.
t
Sounds interesting! I'm using MVI with Rxbinding. Can I replace Rxjava with IO in my case?
s
If you’re using
Observable
or
Flowable
than I wouldn’t recommend it.
You could rewrite to
IO
but RxJava’s types are already “functional types”. You can also use them with Arrow Fx and with the principled APIs of Arrow.
When dealing with such situations I typically have Rx in the Fragment/Activity which I bind with
autodipose
since I only have a single stream in
onResume
(99% of the time).
flatMapIO
is currently missing from the
ObservableK
and
FlowableK
API however.
t
thanks Simon, that's what I'm doing now.
👍 1
s
Nice! Only additional thing I’ve considered is doing
IO
and
suspend
in the non-android layers so I could have MPP support by the end of the year.
👍 1
t
for Rxbinding usecase, do you have any way rewrite it in a more functional way? So we can have easy support for Coroutines channels, rxjava, etc
s
You have an example? Not sure I understood the question correctly
t
I'm working on a bluetooth library, so I need to provide a stream of state of a bluetooth device. I'm heavily using Rxjava now. I want to provide more safe and general solution with Arrow.
s
You can use
arrow-fx-rx
integration which opens up safe combinators for Rx such as
bracketCase
etc
It exposes the exact same API as
IO
but for Rx
I want to provide more safe and general solution with Arrow.
If you want to replace Rx with IO you can rely on recursion with
IO
but I’d recommend sticking with Rx until
arrow-streams
becomes available.
Using Rx with
arrow-fx-rx
should give you similar guarantees, and since it’s Android specific you’re already tied to the JVM anyway.
👍 2
d
to bind effects to Android Lifecycle the setTagIfAbsent could be useful
this way you get automatic cancel/close in the viewmodel, without manual cancel
s
Oh very interesting, I didn’t know about that one. That would be super awesome to have!
d
The problem is that API isn’t really public…
c
Another way of manage lifecycle could be with LifecycleObservers
s
You can integrate with Android Lifecycle using this combinator.
Copy code
fun <A> IOOf<A>.unsafeRunScoped(owner: LifecycleOwner, cancelAt: Lifecycle.Event = Lifecycle.Event.ON_STOP, f: (Either<Throwable, A>) -> Unit): Unit =
  if (owner.lifecycle.currentState == Lifecycle.State.DESTROYED) Unit
  else {
    val disposable = fix().unsafeRunAsyncCancellable(cb = f)

    owner.lifecycle.addObserver(object : LifecycleEventObserver {
      override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
        if (event == cancelAt) disposable.invoke()
      }
    })
  }
🔝 1