monio
The most powerful IO monad implementation in JS, possibly in any language!
A JavaScript library of functional-programming monads (IO, Maybe, Either) for chaining side effects and async code in a predictable way.
Monio is a JavaScript library for developers who want to write code in a functional programming style, specifically using a pattern called monads. A monad is a design pattern from functional programming that helps you chain operations together in a predictable, controlled way, especially when dealing with side effects like network requests, user input, or console output.
The main building block in Monio is called IO. In plain terms, IO is a container that wraps a piece of code that has a side effect, but does not run it until you explicitly say so. This lazy approach means you can build up a sequence of operations and only trigger them when ready. Monio's IO also works naturally with JavaScript promises and async code, so you can write async logic in a style that looks similar to familiar async/await code, while still getting the structural benefits of functional programming.
Beyond IO, the library also provides several companion types. Maybe and Just let you work with values that might or might not exist, without constantly writing null checks. Either lets you model outcomes that are either a success or a failure. IOx is a reactive variant of IO designed for working with streams of events over time. All of these types can be combined and chained together.
Monio is available as an npm package and works in Node.js as well as in browsers. It supports the standard JavaScript module formats (CommonJS, ESM, and UMD), so it fits into most existing project setups.
The library is aimed at JavaScript developers who are curious about or already practicing functional programming. The README includes a detailed guide for beginners who are new to monads, along with live demo applications showing real-world usage patterns.
Where it fits
- Wrap side-effecting code like network calls or console output in a lazy IO monad.
- Handle values that might not exist using Maybe and Just instead of null checks.
- Model success or failure outcomes cleanly using the Either monad.
- React to streams of events over time using the IOx reactive monad.