If I'm understanding you correctly, then fp-ts has the `constant` function to enable what you're describing in #1:
fold(constant('my static fallback'), f)(x)
What sucks about this, as much as it's my preferred pattern, is that without native pattern matching in the language it's unclear which callbacks are for which type constructors. It's not so bad for something like Either, but if you're using something like DatumEither with ~five constructors it's a bit of a mess.
Ah thanks for the suggestions. These reminds me scrounging this article https://dev.to/gcanti/getting-started-with-fp-ts-either-vs-v...
My pet peeve doing this in JS/TS is the fact that writing
``` fold( () => someIdealVal, () => someNonIdealVal )(someAssertion(someValue)); ```
means that those functions passed as the parameters might be instantiated at the execution time rather than on compile time. (This is not proven as the final resulting machine code depends on how good the bundler(webpack)/compiler(tsc)/runtime(v8/rhino) is)
For the sake of performance, I am tempted to write it like this
``` const a = () => someIdealVal const b = () => someNonIdealVal
const someFold = fold(a, b); ```
Writing it like this feels worse for readability. The "story of the function" cannot be told top to bottom, therefore other devs who read this must jump between lines non-sequentially like watching Christopher Nolan's memento.
Rather than pitting readability against performance, I prefer to shelve that fold/pipe/chain pattern for later consideration
2.
I can relate to this. Enums are frustrating especially if you have to write library with it.
I have a pretty good time using this alternative instead. https://medium.com/@martin_hotell/10-typescript-pro-tips-pat... this article point number 4