rubico
🏞 a shallow river in northeastern Italy, just south of Ravenna
[a]synchronous functional programming
import { pipe, map, filter } from 'rubico'
const isOdd = x => x % 2 === 1
const square = x => x ** 2
pipe([
filter(isOdd),
map(square),
])([1, 2, 3, 4, 5]) // [1, 9, 25]
const asyncSquare = async x => x ** 2
pipe([
filter(isOdd),
map(asyncSquare),
])([1, 2, 3, 4, 5]) // Promise { [1, 9, 25] }
Motivation
A note from the author
At a certain point in my career, I grew frustrated with the entanglement of my own code. While looking for something better, I found functional programming. I was excited by the idea of functional composition, but disillusioned by the complex hierarchy of effectful types. I started rubico to capitalize on the prior while rebuking the latter. Many iterations since then, the library has grown into something I personally enjoy using, and continue to use to this day.
rubico's value resides at the intersection of the following principles:
- asynchronous code should be simple
- functional style should not care about async
- functional transformations should be composable, performant, and simple to express
When you use this library, you obtain the freedom that comes only from having those three points fulfilled. The result is something you may enjoy.
Introduction
rubico is a robust, highly optimized syntax for async agnostic functional programming in JavaScript. The style and naming conventions are idiomatic across languages and other libraries; using this library should feel second nature. Just like regular vanilla JavaScript syntax and operators, rubico syntax operates predictably on vanilla JavaScript types. When you use this library, you can stop worrying about the complex fluff of Promise management. When something goes wrong, rubico throws meaningful and ergonomic errors. You should use this library if you want to become a more effective programmer, write cleaner and more concise code, or harness the expressive power of functional programming in production.
Here are my recommendations for getting started.
- check out the docs
- take the tour
- use rubico in a project
- at your leisure, peruse the awesome resources
- help with rubico
API
const {
pipe, fork, assign,
tap, tryCatch, switchCase,
map, filter, reduce, transform, flatMap,
any, all, and, or, not,
eq, gt, lt, gte, lte,
get, pick, omit,
} = rubico
Installation
with npm
npm i rubico
browser script, global rubico
<script src="https://unpkg.com/rubico"></script>
browser module
import rubico from 'https://unpkg.com/rubico/es.js'
System Requirements
- minimum node version: 10.3
- minimum Chrome version: 63
- minimum Firefox version: 57
- minimum Edge version: 79
- minimum Safari version: 11.1
Awesome Resources
Beginner
- Practical Functional Programming in JavaScript - Why it's worth it
- Practical Functional Programming in JavaScript - Data last
- Practical Functional Programming in JavaScript - Side Effects and Purity
- Practical Functional Programming in JavaScript - Intro to Transformation
- Practical Functional Programming in JavaScript - Techniques for Composing Data
- Practical Functional Programming in JavaScript - Control Flow
Advanced
Contributing
Your feedback and contributions are welcome. If you have a suggestion, please raise an issue. Prior to that, make sure to search through the issues first in case your suggestion has been made already. If you decide to work on an issue, please announce on the issue thread that you will work on it.
Enhancements should follow the principles of the library:
- asynchronous code should be simple
- functional style should not care about async
- functional transformations should be composable, performant, and simple to express
Pull requests should provide some basic context and link the relevant issue. My intention is that progress on the library follow an issue -> pull request format. See this pull request for an example.
If you are interested in contributing, the help wanted tag is a good place to start.
License
rubico is MIT Licensed.