https://kotlinlang.org logo
Title
r

reactormonk

07/07/2022, 1:05 PM
Is there an equivalent
trySendBlocking
to send exceptions down the channel?
j

Joffrey

07/07/2022, 1:06 PM
close(Throwable)
?
r

reactormonk

07/07/2022, 1:07 PM
Doesn't that also close the channel? I assumed the mental model of FS2 scala channels, where after an exception trudges along, you can keep receiving messages, if you handle the exception along the way.
j

Joffrey

07/07/2022, 1:09 PM
Yes, it closes the channel too. If you don't want this behavior, you can't really use an exception (it would crash the collector, so the collection would stop anyway). What you can do instead is materialize the exception using your own type (like a
Result
) and send it normally like other elements
kotlin doesn't happen to have a built-in Result with a custom error type?
j

Joffrey

07/07/2022, 1:12 PM
nope
but it's really easy to write your own domain-specific sealed class for it
s

simon.vergauwen

07/07/2022, 1:12 PM
Arrow offers an
Either
type, and in Arrow Fx Coroutines it offers similar functionality as Cats-effect and FS2. https://github.com/arrow-kt/arrow
r

reactormonk

07/07/2022, 1:12 PM
Yeah, probably arrow time
s

simon.vergauwen

07/07/2022, 1:13 PM
It also exposes a couple of powerful DSLs as alternatives to monadic operators
r

reactormonk

07/07/2022, 1:14 PM
🤔 I think I'll stuff it into a standard
Result
, until I need to change it. Probably sooner than I'd like.
... then I'll get back to Arrow, on my list anyway.
s

simon.vergauwen

07/07/2022, 1:18 PM
Result is great if you just need to work over
Throwable
. If you end up using Arrow, and you have any doubts or questions there are many people in#arrow that'd gladly help you out!
r

reactormonk

07/07/2022, 1:20 PM
Got a "from Haskell to Arrow" somewhere? Or Scala works too 😄
s

simon.vergauwen

07/07/2022, 1:22 PM
Uhm, not really. It' been on our to-do list for a while, but writing/maintaining docs is hard 😅 There should not be any surprises in Arrow if you already have perquisite knowledge. The goal of Arrow is to offer idiomatic FP in Kotlin with low overhead and a low learning curve.
Best place to get started would be in the Arrow core docs, https://arrow-kt.io/docs/core/