Been stuck in TypeScript, and using their Unions, you have to use
switch statements, and they can get nested quickly. In my head, I see the red squiggles from that elm-review rule saying “You can’t nest pattern matching beyond 1 level, we suggest Maybe.andThen”. Figured if I knew how to solve this in Elm, I could carry over the same idea to TypeScript.
Some quick googling: The Scala kids say if not a dual Monad, “Eitherise” your type so you can do a sort of “andThen”. This may not work if you don’t have sum type that has a zero or error equivalent; mine don’t.
The Rust/F# cats say use their yield, but… again, this only works for Either’s.
The Elixir examples, and even a SonarQube rule equivalent, just say to make functions that abstract away the choice, and you can then have 3 functions together to remove the nesting entirely. I may just do this, but curious if there are other ways.