3 ms·
Hi HN. I wrote an Option object for javascript and typescript. Lots of functional programming libraries already exist, in addition to several standalone JS/TS
by bern4444 5y ago
Hi HN.
I wrote an Option object for javascript and typescript.
Lots of functional programming libraries already exist, in addition to several standalone JS/TS option packages. So why another?
I wanted a high quality, stand-alone, fully typed package with great behavior. I believe this is the best package on npm for working with Options.
Benefits
- Excellent TypeScript support. The developer experience is exceptional.
- Zero production dependencies. Even the dev dependency list is extremely small.
- Safe and powerful implementation of some methods. Flatten in most packages will throw an error called on Nones.This package never throws. Better implementation of contains method - this package lets you pass in a custom equality function (for example deep object equality from another package or maybe based on a specific property). By default the function is ===. Suitable for primitive values.
- Static (aka curried) versions of map (also called lift) and flatMap. This allows for converting functions that work on non option values to their equivalent that work on Optionals and allows you to reuse your existing code as much as possible.
- Great documentation. Lots of examples in TSDocs that will show in your editor for support. Tests demonstrating usage, and extensive information in the README.
- Simple (but powerful) implementation. Makes for a great example to follow along for anyone learning functional programming while providing an easy way to get working code for all projects.
I hope you take a look and find this interesting or useful!