{"id":30180638,"url":"https://github.com/richytong/rubico","last_synced_at":"2025-08-12T08:02:00.168Z","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-07-05T12:13:09.000Z","size":4636,"stargazers_count":282,"open_issues_count":56,"forks_count":16,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-08-06T09:07:23.732Z","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,"zenodo":null}},"created_at":"2019-11-03T09:20:01.000Z","updated_at":"2025-08-04T21:41:21.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,"purl":"pkg:github/a-synchronous/rubico","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","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-synchronous%2Frubico/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270024697,"owners_count":24514054,"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","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-08-12T08:01:29.784Z","updated_at":"2025-08-12T08:02:00.148Z","avatar_url":"https://github.com/a-synchronous.png","language":"JavaScript","funding_links":[],"categories":["Modules","基础设施"],"sub_categories":["Online Playgrounds","Assistants","Utils","JAM Stack/静态站点"],"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) ([~7.7 kB minified and gzipped](https://unpkg.com/rubico/dist/rubico.min.js)) [Transducer module](https://unpkg.com/rubico/dist/Transducer.js) ([~1.5kb minified and gzipped](https://unpkg.com/rubico/dist/Transducer.min.js))\n\nwith [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm):\n```bash\nnpm i rubico\n```\n\n\nrequire rubico in [CommonJS](https://nodejs.org/docs/latest/api/modules.html#modules-commonjs-modules):\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\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 [A]synchronous 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 [A]synchronous Functional Programming, any function may be asynchronous and return a promise. All promises are resolved for their values 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 eager and lazy APIs. The eager API takes all required arguments and executes at once, while the lazy API takes only the setup arguments and returns a function that executes later. 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 through its `Transducer` module. You can consume these transducers with rubico's `transform` and `compose` operators. You can use `compose` 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 rubico operators have property functions that have various asynchronous behavior, e.g.\n * `map` - applies a mapper function concurrently\n * `map.pool` - applies a mapper function concurrently with a concurrency limit\n * `map.series` - applies 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, please create a pull request.\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## Blog\nLearn more about rubico and [A]synchronous Functional Programming at [https://rubico.land/blog](https://rubico.land/blog).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichytong%2Frubico","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frichytong%2Frubico","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichytong%2Frubico/lists"}