Closed hellos3b closed 3 years ago
If this is only a semantics issue, there is also .caseOf()
and .either()
that achieve similar functionality without the "map" naming.
That being said, I think you may be looking for EitherAsync.run()
(afaik very similar to fluture's fork()
), res.send
is a side effect-ing function and I feel those a better represented using the *Async variants.
disclaimer: Take my suggestions with a grain of salt, I'm by no means an expert.
As @pyrho mentioned, there are a lot of options and all of them are fine. I don't think there's a need for another method. If you want to be explicit about the side-effects of the handler the best solution would be:
const route = (req: Request, res: Response) => {
codec
.decode(req.body)
.map(transform)
.ifLeft(handleError(req))
.ifRight(res.send)
}
So while using this lib, I find often my "app" revolves around an
Either
. Take for example, a REST request in express:One thing that feels kind of wrong is using
bimap
for the end results/effects, as I'm not transforming the Either. I think it'd be nice to have an explicit method that doesn't transform the Either, similar toArray.forEach
vsArray.map
. The Fluture library usesfork
which I think represents it well