In a web application, I have an action that can fail in various ways or ultimately succeed.
In this context, success and failure are represented by SimpleResult subclasses (representing the HTTP response)
I am using monadic operations on scalaz / to encode my algorithm with something like:
val result = for {
user <- fetchUser \/> Forbidden("you must be connected to perform this action")
basket <- user.basket \/> NotFound("no basket !")
...
} yield Ok(someBasketView(user, basket))
therefore it will be SimpleResult \/ SimpleResult, and I have to write this:
result fold (identity, identity)
to extract the result from a disjunction, which I find pretty ugly.
Is there an abstraction that captures such a “clearly simplifiable structure”? or perhaps disjunction is not a proper abstraction in this regard?
source
share