1.
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