you might be looking for something like https://github.com/zalando-stups/cats.match @sinistral
Thanks for the link @mccraigmccraig. I'll look into that and instaskip; hopefully that will give me a better idea of the patterns (no pun intended) that make sense.
i haven't used cats.match
myself @sinistral, so can't comment on how straightforward or effective it is - i have surprisingly little code which needs to process error states, so i've been ok with the more awkward branch style approach
Is that an acceptable approach? Every time I use a branch-*
, I can't help but feel that I should be using something like fmap
instead. Between branch-*
and with-context
, I feel like I'm doing something wrong; I feel like I'm adding the kind of boilerplate that monads are monads are supposed to alleviate. (As I said ... very naïve questions, sorry)
fmap
won't do anything to errored values - that's the point of short-circuit evaulation
a quick survey of my codebase - we've got 80kloc and 1000 uses of mlet - but only 20 branches - most of the branches are at component boundaries, doing things like formatting an http error response, so they aren't very common
your use-case could be different of course, in which case i'd go for a pattern matching approach
No, that reinforces my feeling that I'm doing something wrong, and that I'm resorting to branch
when I shouldn't be. In most cases, I'd like short-circuit evaluation, but I'm using branch
to package function return values correctly ... which probably means that I'm not using return
as I should.
I'll break my use-case down into a simpler example when I have a bit more time; that will give me something concrete to talk about (and hopefully help me to answer my questions on my own).
Thanks for taking the time to respond @mccraigmccraig.