Youssef Shoaib [MOD]
04/12/2024, 10:43 PMtry-catch
inside composables was planned. Is that still being worked on? I'm trying to use Arrow's Raise
with Compose and Molecule, which I guess makes it a doubly-niche use case.Stylianos Gakis
04/12/2024, 10:48 PMYoussef Shoaib [MOD]
04/12/2024, 10:51 PMOption
, but I'd like to instead have the ability to just do raise(None)
.
Sorry if it wasn't clear, but I mentioned try-catch
because that's what Raise
uses to function. I'm not directly using that, I'm instead `raise`ing inside an option
blockStylianos Gakis
04/12/2024, 10:52 PMYoussef Shoaib [MOD]
04/12/2024, 11:16 PM@Test
fun filtering2() = runTest {
lateinit var itemChannel : SendChannel<Int>
val items = callbackFlow {
itemChannel = this
awaitClose()
}
val flow = moleculeFlow(RecompositionMode.Immediate) {
option {
val item by items.collectAsState(0)
if (item == 2) raise(None) else item
}
}.filterIsInstance<Some<Int>>().map { it.value }
flow.test(10.seconds) {
awaitItem() shouldBe 0
itemChannel.send(1)
awaitItem() shouldBe 1
itemChannel.send(2)
itemChannel.send(3)
awaitItem() shouldBe 3
cancel()
}
}
However, when trying to extract the plumbing out of it, I get a `ComposeRuntimeError`:
@Test
fun filtering2() = runTest {
lateinit var itemChannel : SendChannel<Int>
val items = callbackFlow {
itemChannel = this
awaitClose()
}
val flow = myMoleculeFlow {
val item by items.collectAsState(0)
if (item == 2) raise(None) else item
}
flow.test(10.seconds) {
awaitItem() shouldBe 0
itemChannel.send(1)
awaitItem() shouldBe 1
itemChannel.send(2)
itemChannel.send(3)
awaitItem() shouldBe 3
cancel()
}
}
inline fun <T> myMoleculeFlow(
crossinline body: @Composable OptionRaise.() -> T
) = moleculeFlow(RecompositionMode.Immediate) {
option {
body()
}
}.filterIsInstance<Some<T>>().map { it.value }
Youssef Shoaib [MOD]
04/12/2024, 11:18 PMStylianos Gakis
04/12/2024, 11:39 PMStylianos Gakis
04/12/2024, 11:42 PMYoussef Shoaib [MOD]
04/12/2024, 11:44 PMinline
doesn't play that nicely with it (my expectation would be that manually inlining an inline
method shouldn't change whether the code works or not). I wonder if there's a "compose way" to do this.Stylianos Gakis
04/12/2024, 11:47 PMthis
is here when you say a compose way to do this.
If you show like the real use case here you have with the existing code it might be much easier to discussYoussef Shoaib [MOD]
04/12/2024, 11:49 PMfilter
ing unwanted values.Stylianos Gakis
04/12/2024, 11:50 PMStylianos Gakis
04/12/2024, 11:51 PMYoussef Shoaib [MOD]
04/12/2024, 11:53 PMnull
value from any other possibly-filtering function I callo
> normal non-compose function which takes input and returns the filtered output back
The issue is that I want to filter based on flows that were `collectAsState`ed.
I want to be able to basically "cancel" a current composition if you will. Maybe that's the terminology I should be using. I want to cancel the current composition because it can't produce a useful value, and instead I'd like to wait until another state change causes a recompositionStylianos Gakis
04/12/2024, 11:58 PMYoussef Shoaib [MOD]
04/13/2024, 12:01 AMOption
, which is inelegant, or with exceptions and Raise
, which compose doesn't support easilyStylianos Gakis
04/13/2024, 12:05 AMRaise
need to be a composable itself? And not a normal function?Youssef Shoaib [MOD]
04/13/2024, 12:14 AMFlow
, or it can be a Composable and return an Option
. The annoying bit, I guess, is that both aren't possible at once, but I guess that's not that significant of a drawbackPablichjenkov
04/13/2024, 5:55 PMStylianos Gakis
04/13/2024, 5:58 PMPablichjenkov
04/13/2024, 6:06 PMStylianos Gakis
04/13/2024, 6:08 PMPablichjenkov
04/13/2024, 6:10 PM