Is there an equivalent `trySendBlocking` to send e...
# coroutines
r
Is there an equivalent
trySendBlocking
to send exceptions down the channel?
j
close(Throwable)
?
r
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
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
nope
but it's really easy to write your own domain-specific sealed class for it
s
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
Yeah, probably arrow time
s
It also exposes a couple of powerful DSLs as alternatives to monadic operators
r
🤔 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
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
Got a "from Haskell to Arrow" somewhere? Or Scala works too 😄
s
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/