# ryne

> 🏞 a shallow river in northeastern Italy, just south of Ravenna

Latest version **0.2.9** (published 2020-04-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install ryne
pnpm add ryne
yarn add ryne
bun add ryne
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.2.9 |
| Published | 2020-04-27 |
| First published | 2020-04-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 543 B |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 283 |
| Author | Richard Tong |
| Maintainers | richytong |
| Keywords | rubico, composition, callback, async, await, functional, fp, point-free, promise, promises, toolkit, tacit, utils, utility |

## Links

- npm: https://www.npmjs.com/package/ryne
- Repository: https://github.com/richytong/rubico
- Homepage: https://rubico.land
- Issues: https://github.com/richytong/rubico/issues
- npm.io page: https://npm.io/package/ryne

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 0.2.9 (latest) — 2020-04-27

## README

# [Rubico](https://rubico.land/)
![rubico](https://rubico.land/assets/rubico-logo-3-3-300.jpg)
> a shallow river in northeastern Italy, just south of Ravenna

Source code: [GitHub](https://github.com/a-synchronous/rubico) |
License: [CFOSS](https://cloutsworld.com/en-us/legal/license/cfoss)

![Node.js CI](https://github.com/a-synchronous/rubico/workflows/Node.js%20CI/badge.svg)
[![codecov](https://codecov.io/gh/a-synchronous/rubico/branch/master/graph/badge.svg)](https://codecov.io/gh/a-synchronous/rubico)
[![npm version](https://img.shields.io/npm/v/rubico.svg?style=flat)](https://www.npmjs.com/package/rubico)

## [A]synchronous Functional Programming

A program is a tree of synchronous or asynchronous functions.

A program can be a combination of programs from different paradigms.

```javascript [playground]
const { pipe, map, filter } = rubico

const isOdd = number => number % 2 == 1

const asyncSquare = async number => number ** 2

const numbers = [1, 2, 3, 4, 5]

pipe(
  numbers, 
  filter(isOdd),
  map(asyncSquare),
  console.log,
)
```

## Installation
[Core build](https://cdn.jsdelivr.net/npm/rubico/index.js) ([~8.3 kB minified and gzipped](https://cdn.jsdelivr.net/npm/rubico/dist/rubico.min.js)) [Transducer module](https://cdn.jsdelivr.net/npm/rubico/dist/Transducer.js) ([~1.7kb minified and gzipped](https://cdn.jsdelivr.net/npm/rubico/dist/Transducer.min.js))

with [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm):
```bash
npm i rubico
```

require Rubico with Node.js [CommonJS modules](https://nodejs.org/docs/latest/api/modules.html#modules-commonjs-modules):
```javascript
// import rubico core globally
require('rubico/global')

// import rubico core as rubico
const rubico = require('rubico')

// import an operator from rubico core
const pipe = require('rubico/pipe')

// import rubico/x as x
const x = require('rubico/x')

// import an operator from rubico/x
const defaultsDeep = require('rubico/x/defaultsDeep')

// import rubico's Transducer module
const Transducer = require('rubico/Transducer')
```

import Rubico in the browser:
```html [htmlmixed]
<!-- import rubico core globally -->
<script src="https://cdn.jsdelivr.net/npm/rubico/dist/global.min.js"></script>

<!-- import rubico core as rubico -->
<script src="https://cdn.jsdelivr.net/npm/rubico/dist/rubico.min.js"></script>

<!-- import an operator from rubico core -->
<script src="https://cdn.jsdelivr.net/npm/rubico/dist/pipe.min.js"></script>

<!-- import an operator from rubico/x -->
<script src="https://cdn.jsdelivr.net/npm/rubico/dist/x/defaultsDeep.min.js"></script>

<!-- import rubico's Transducer module -->
<script src="https://cdn.jsdelivr.net/npm/rubico/dist/Transducer.min.js"></script>
```

import Rubico with Node.js [ECMAScript modules](https://nodejs.org/api/esm.html):
```javascript
// import rubico core globally
import "rubico/global.mjs"

// import rubico core as rubico
import rubico from "rubico"

// import an operator from rubico core
import pipe from "rubico/pipe.mjs"

// import rubico/x as x
import x from "rubico/x/index.mjs"

// import an operator from rubico/x
import defaultsDeep from "rubico/x/defaultsDeep.mjs"

// import rubico's Transducer module
import Transducer from "rubico/Transducer.mjs"
```

## 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 redundancy of effectful types. I started Rubico to capitalize on the prior while rebuking the latter.

[A]synchronous functional programming is founded on 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 import this library, you obtain the freedom that comes from having those three points fulfilled. The result is something you may enjoy.

## Introduction

Rubico is a library for [A]synchronous Functional Programming in JavaScript. The library supports a simple and composable functional style in asynchronous environments.

```javascript
const {

  // function composition
  pipe, compose, tap,

  // conditional operators
  switchCase,

  // error handling
  tryCatch,

  // data construction
  all, assign, get, set, pick, omit,

  // iteration
  forEach,

  // transformation
  map, filter, reduce, transform, flatMap,

  // data testing
  some, every,

  // logical operators
  and, or, not,

  // comparison operators
  eq, gt, lt, gte, lte,

  // partial application
  thunkify, always, curry, __,

} = rubico
```

With [A]synchronous Functional Programming, any function may be asynchronous and return a promise, and arguments may be promises as well. If a promise is provided to a Rubico operator in argument position, the Rubico operator will resolve the promise.

```javascript [playground]
const helloPromise = Promise.resolve('hello')

pipe(
  helloPromise, // helloPromise is resolved for 'hello'

  async greeting => `${greeting} world`,
  // the Promise returned from the async function is resolved
  // and the resolved value is passed to console.log

  console.log,
)
```

All Rubico operators support both immediate and lazy interfaces. The immediate interface takes all required arguments and executes at once, while the lazy interface takes only the setup arguments and returns a function that only expects the data arguments. This dual interface supports a natural and composable code style.

```javascript [playground]
const myObj = { a: 1, b: 2, c: 3 }

// the first map call is immediate
const myDuplicatedSquaredObject = map(myObj, pipe(
  number => [number, number],

  // the second map call is lazy
  map(number => number ** 2),
))

console.log(myDuplicatedSquaredObject)
```

The Rubico operators are versatile and act on a wide range of vanilla JavaScript types to create declarative, extensible, and async-enabled function compositions. The same operator `map` can act on an array and also a `Map` data structure.

```javascript [playground]
const { pipe, tap, map, filter } = rubico

const toTodosUrl = id => `https://jsonplaceholder.typicode.com/todos/${id}`

const todoIDs = [1, 2, 3, 4, 5]

pipe(todoIDs, [

  // fetch todos per id of todoIDs
  map(pipe(
    toTodosUrl,
    fetch,
    response => response.json(),

    tap(console.log),
  )),

  // group the todos by id in a new Map
  function createTodosMap(todos) {
    const todosMap = new Map()
    for (const todo of todos) {
      const { userId: id } = todo
      if (todosMap.has(id)) {
        todosMap.get(id).push(todo)
      } else {
        todosMap.set(id, [todo])
      }
    }
    return todosMap
  },

  // filter for completed todos
  // map iterates through each value (array of todos) of the todosMap
  // filter iterates through each todo of the arrays of todos
  map(filter(function didComplete(todo) {
    return todo.completed
  })),

  tap(console.log),
])
```

Rubico offers transducers via the `Transducer` module, which is combined with Rubico's `transform` and `compose` operators. The `transform` operator executes a `Transducer` with a variety of data types, and the `compose` operator chains a left-to-right composition of transducers.

```javascript [playground]
const isOdd = number => number % 2 == 1

const asyncSquare = async number => number ** 2

const generateNumbers = function* () {
  yield 1
  yield 2
  yield 3
  yield 4
  yield 5
}

pipe(
  generateNumbers(),
  transform(compose(
    Transducer.filter(isOdd),
    Transducer.map(asyncSquare),
  ), []),
  console.log,
)
```

For advanced asynchronous expressions, some of Rubico's operators have property operators that support varied asynchronous behavior, e.g.
 * `map` - applies a mapper function concurrently
 * `map.pool` - applies a mapper function concurrently with a concurrency limit
 * `map.series` - applies a mapper function serially

For more functions beyond the core operators, please visit `rubico/x`. You can find the full documentation at [rubico.land/docs](https://rubico.land/docs).

## Benchmarks
Please find the published benchmark output inside the [benchmark-output](https://github.com/a-synchronous/rubico/tree/master/benchmark-output) folder. You can run the benchmarks on your own system with the following command:
```
npm run bench
```

## Contributing
Your feedback and contributions are welcome. If you have a suggestion, please raise an issue. Prior to that, please search through the issues first in case your suggestion has been made already. If you decide to work on an issue, please create a pull request.

Pull requests should provide some basic context and link the relevant issue. Here is an [example pull request](https://github.com/a-synchronous/rubico/pull/12). If you are interested in contributing, the [help wanted](https://github.com/a-synchronous/rubico/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) tag is a good place to start.

For more information please see [CONTRIBUTING.md](https://github.com/a-synchronous/rubico/blob/master/CONTRIBUTING.md)

## License
Rubico is distributed under the [CFOSS License](https://cloutsworld.com/en-us/legal/license/cfoss).

## Support
 * minimum Node.js version: 16
 * minimum Chrome version: 63
 * minimum Firefox version: 57
 * minimum Edge version: 79
 * minimum Safari version: 11.1

## Blog
Learn more about Rubico and [A]synchronous Functional Programming at [https://rubico.land/blog](https://rubico.land/blog).

---
_Source: https://npm.io/package/ryne · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
