{"id":13510242,"url":"https://github.com/a-synchronous/rubico","last_synced_at":"2025-05-15T12:06:32.694Z","repository":{"id":37951644,"uuid":"219276883","full_name":"a-synchronous/rubico","owner":"a-synchronous","description":"[a]synchronous functional programming","archived":false,"fork":false,"pushed_at":"2025-03-14T22:44:11.000Z","size":4374,"stargazers_count":280,"open_issues_count":46,"forks_count":15,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-05-09T01:53:18.103Z","etag":null,"topics":["async","async-await","asynchronous","combinators","concurrent","function-composition","functional-programming","generator","iterator","javascript","monad","mux","node","operator","parallel","pointfree","promise","series","tacit","transducers"],"latest_commit_sha":null,"homepage":"https://rubico.land","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/a-synchronous.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-03T09:20:01.000Z","updated_at":"2025-04-25T06:11:13.000Z","dependencies_parsed_at":"2023-07-19T09:12:48.568Z","dependency_job_id":"ecd77e8f-f08c-49e6-a9bb-bedda5b13d35","html_url":"https://github.com/a-synchronous/rubico","commit_stats":{"total_commits":2283,"total_committers":8,"mean_commits":285.375,"dds":"0.037231712658782334","last_synced_commit":"abeb57fe778b8956df818f109036eafa40a1179c"},"previous_names":["richytong/fnal","richytong/rubico"],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-synchronous%2Frubico","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-synchronous%2Frubico/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-synchronous%2Frubico/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-synchronous%2Frubico/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/a-synchronous","download_url":"https://codeload.github.com/a-synchronous/rubico/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254337613,"owners_count":22054253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","async-await","asynchronous","combinators","concurrent","function-composition","functional-programming","generator","iterator","javascript","monad","mux","node","operator","parallel","pointfree","promise","series","tacit","transducers"],"created_at":"2024-08-01T02:01:30.306Z","updated_at":"2025-05-15T12:06:27.683Z","avatar_url":"https://github.com/a-synchronous.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","node","Libraries","Modules"],"sub_categories":["Utils"],"readme":"# [rubico](https://rubico.land/)\n![rubico](https://raw.githubusercontent.com/a-synchronous/assets/master/rubico-logo.png)\n\u003e a shallow river in northeastern Italy, just south of Ravenna\n\n![Node.js CI](https://github.com/a-synchronous/rubico/workflows/Node.js%20CI/badge.svg)\n[![codecov](https://codecov.io/gh/a-synchronous/rubico/branch/master/graph/badge.svg)](https://codecov.io/gh/a-synchronous/rubico)\n[![npm version](https://img.shields.io/npm/v/rubico.svg?style=flat)](https://www.npmjs.com/package/rubico)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\n### [a]synchronous functional programming\n\n```javascript [playground]\nconst { pipe, map, filter } = rubico\n\nconst isOdd = number =\u003e number % 2 == 1\n\nconst asyncSquare = async number =\u003e number ** 2\n\nconst numbers = [1, 2, 3, 4, 5]\n\npipe(numbers, [\n  filter(isOdd),\n  map(asyncSquare),\n  console.log, // [1, 9, 25]\n])\n```\n\n# Installation\n[Core build](https://unpkg.com/rubico/index.js) ([~9.8 kB minified and gzipped](https://unpkg.com/rubico/dist/rubico.min.js))\n\nwith `npm`\n```bash\nnpm i rubico\n```\n\nrequire `rubico` in CommonJS.\n```javascript\n// import rubico core globally\nrequire('rubico/global')\n\n// import rubico core as rubico\nconst rubico = require('rubico')\n\n// import an operator from rubico core\nconst pipe = require('rubico/pipe')\n\n// import rubico/x as x\nconst x = require('rubico/x')\n\n// import an operator from rubico/x\nconst defaultsDeep = require('rubico/x/defaultsDeep')\n\n// import rubico's Transducer module\nconst Transducer = require('rubico/Transducer')\n```\n\nimport `rubico` in the browser.\n```html [htmlmixed]\n\u003c!-- import rubico core globally --\u003e\n\u003cscript src=\"https://unpkg.com/rubico/dist/global.min.js\"\u003e\u003c/script\u003e\n\n\u003c!-- import rubico core as rubico --\u003e\n\u003cscript src=\"https://unpkg.com/rubico/dist/rubico.min.js\"\u003e\u003c/script\u003e\n\n\u003c!-- import an operator from rubico core --\u003e\n\u003cscript src=\"https://unpkg.com/rubico/dist/pipe.min.js\"\u003e\u003c/script\u003e\n\n\u003c!-- import an operator from rubico/x --\u003e\n\u003cscript src=\"https://unpkg.com/rubico/dist/x/defaultsDeep.min.js\"\u003e\u003c/script\u003e\n\n\u003c!-- import rubico's Transducer module --\u003e\n\u003cscript src=\"https://unpkg.com/rubico/dist/Transducer.min.js\"\u003e\u003c/script\u003e\n```\n\n# Motivation\n\nA note from the author\n\u003e 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. Many iterations since then, the library has grown into something I personally enjoy using, and continue to use to this day.\n\nrubico is founded on the following principles:\n * asynchronous code should be simple\n * functional style should not care about async\n * functional transformations should be composable, performant, and simple to express\n\nWhen you import this library, you obtain the freedom that comes from having those three points fulfilled. The result is something you may enjoy.\n\n# Introduction\n\nrubico is a library for async-enabled functional programming in JavaScript. The library supports a simple and composable functional style in asynchronous environments.\n\n```javascript\nconst {\n  // compose functions\n  pipe, compose, tap,\n\n  // control flow\n  switchCase,\n\n  // handle errors\n  tryCatch,\n\n  // compose data\n  all, assign, get, set, pick, omit,\n\n  // iterate\n  forEach,\n\n  // transform data\n  map, filter, reduce, transform, flatMap,\n\n  // compose predicates\n  and, or, not, some, every,\n\n  // comparison operators\n  eq, gt, lt, gte, lte,\n\n  // partial application\n  thunkify, always, curry, __,\n} = rubico\n```\n\nWith async-enabled, or [a]synchronous, functional programming, functions provided to the rubico operators may be asynchronous and return a Promise. Any promises in argument position are also resolved before continuing with the operation.\n\n```javascript [playground]\nconst helloPromise = Promise.resolve('hello')\n\npipe(helloPromise, [ // helloPromise is resolved for 'hello'\n  async greeting =\u003e `${greeting} world`,\n  // the Promise returned from the async function is resolved\n  // and the resolved value is passed to console.log\n\n  console.log, // hello world\n])\n```\n\nAll rubico operators support both an eager and a lazy API. The eager API takes all required arguments and executes at once, while its lazy API takes only the non-data arguments and executes lazily, returning a function that expects the data arguments. This dual API supports a natural and composable code style.\n\n```javascript [playground]\nconst myObj = { a: 1, b: 2, c: 3 }\n\n// the first use of map is eager\nconst myDuplicatedSquaredObject = map(myObj, pipe([\n  number =\u003e [number, number],\n\n  // the second use of map is lazy\n  map(number =\u003e number ** 2),\n]))\n\nconsole.log(myDuplicatedSquaredObject)\n// { a: [1, 1], b: [4, 4], c: [9, 9] }\n```\n\nThe 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.\n\n```javascript [playground]\nconst { pipe, tap, map, filter } = rubico\n\nconst toTodosUrl = id =\u003e `https://jsonplaceholder.typicode.com/todos/${id}`\n\nconst todoIDs = [1, 2, 3, 4, 5]\n\npipe(todoIDs, [\n\n  // fetch todos per id of todoIDs\n  map(pipe([\n    toTodosUrl,\n    fetch,\n    response =\u003e response.json(),\n\n    tap(console.log),\n    // { userId: 1, id: 4, title: 'et porro tempora', completed: true }\n    // { userId: 1, id: 1, title: 'delectus aut autem', completed: false }\n    // { userId: 1, id: 3, title: 'fugiat veniam minus', completed: false }\n    // { userId: 1, id: 2, title: 'quis ut nam facilis...', completed: false }\n    // { userId: 1, id: 5, title: 'laboriosam mollitia...', completed: false }\n  ])),\n\n  // group the todos by userId in a new Map\n  function createUserTodosMap(todos) {\n    const userTodosMap = new Map()\n    for (const todo of todos) {\n      const { userId } = todo\n      if (userTodosMap.has(userId)) {\n        userTodosMap.get(userId).push(todo)\n      } else {\n        userTodosMap.set(userId, [todo])\n      }\n    }\n    return userTodosMap\n  },\n\n  // filter for completed todos\n  // map iterates through each value (array of todos) of the userTodosMap\n  // filter iterates through each todo of the arrays of todos\n  map(filter(function didComplete(todo) {\n    return todo.completed\n  })),\n\n  tap(console.log),\n  // Map(1) {\n  //   1 =\u003e [ { userId: 1, id: 4, title: 'et porro tempora', completed: true } ]\n  // }\n])\n```\n\nrubico offers transducers in its `Transducer` module. You can consume these transducers with the `transform` and `compose` operators. You should use `compose` over `pipe` to chain a left-to-right composition of transducers.\n\n```javascript [playground]\nconst isOdd = number =\u003e number % 2 == 1\n\nconst asyncSquare = async number =\u003e number ** 2\n\nconst generateNumbers = function* () {\n  yield 1\n  yield 2\n  yield 3\n  yield 4\n  yield 5\n}\n\npipe(generateNumbers(), [\n  transform(compose([\n    Transducer.filter(isOdd),\n    Transducer.map(asyncSquare),\n  ]), []),\n  console.log, // [1, 9, 25]\n])\n```\n\nFor advanced asynchronous use cases, some of the operators have property functions that have different asynchronous behavior, e.g.\n * `map` - apply a mapper function concurrently\n * `map.pool` - apply a mapper function concurrently with a concurrency limit\n * `map.series` - apply a mapper function serially\n\nFor more functions beyond the core operators, please visit `rubico/x`. You can find the full documentation at [rubico.land/docs](https://rubico.land/docs).\n\n# Benchmarks\nPlease 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:\n```\nnpm run bench\n```\n\n# Contributing\nYour 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, or feel like taking initiative and contributing anything at all, feel free to create a pull request and I will get back to you shortly.\n\nPull 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.\n\nFor more information please see [CONTRIBUTING.md](/CONTRIBUTING.md)\n\n# License\nrubico is [MIT Licensed](https://github.com/a-synchronous/rubico/blob/master/LICENSE).\n\n# Support\n * minimum Node.js version: 16\n * minimum Chrome version: 63\n * minimum Firefox version: 57\n * minimum Edge version: 79\n * minimum Safari version: 11.1\n\n# Awesome Resources\n[rubico simplifies asynchronous code](https://dev.to/richytong/rubico-a-synchrnous-functional-syntax-motivation-20hf)\n\u003cbr\u003e\n[Practical Functional Programming in JavaScript - Side Effects and Purity](https://dev.to/richytong/practical-functional-programming-in-javascript-side-effects-and-purity-revised-420h)\n\u003cbr\u003e\n[Practical Functional Programming in JavaScript - Techniques for Composing Data](https://dev.to/richytong/practical-functional-programming-in-javascript-techniques-for-composing-data-c39)\n\u003cbr\u003e\n[Practical Functional Programming in JavaScript - Error Handling](https://dev.to/richytong/practical-functional-programming-in-javascript-error-handling-8g5)\n\n# Blog\nCheck out the rubico blog at [https://rubico.land/blog](https://rubico.land/blog)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-synchronous%2Frubico","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa-synchronous%2Frubico","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-synchronous%2Frubico/lists"}