{"id":13394278,"url":"https://github.com/staltz/callbag-basics","last_synced_at":"2025-05-15T02:02:48.932Z","repository":{"id":40003183,"uuid":"119371155","full_name":"staltz/callbag-basics","owner":"staltz","description":"👜 Tiny and fast reactive/iterable programming library","archived":false,"fork":false,"pushed_at":"2023-04-20T06:28:40.000Z","size":252,"stargazers_count":1652,"open_issues_count":8,"forks_count":43,"subscribers_count":41,"default_branch":"master","last_synced_at":"2024-12-24T20:38:16.545Z","etag":null,"topics":["callbacks","callbag","iterables","observables","reactive"],"latest_commit_sha":null,"homepage":"","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/staltz.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"patreon":"andrestaltz"}},"created_at":"2018-01-29T10:58:59.000Z","updated_at":"2024-12-12T07:00:06.000Z","dependencies_parsed_at":"2024-01-13T17:11:22.898Z","dependency_job_id":"b152446c-9123-4b72-afc6-7173a52e7b5e","html_url":"https://github.com/staltz/callbag-basics","commit_stats":{"total_commits":53,"total_committers":9,"mean_commits":5.888888888888889,"dds":"0.41509433962264153","last_synced_commit":"ef0e93633817a1e19ac3ce00180e4f862186e126"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/staltz%2Fcallbag-basics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/staltz%2Fcallbag-basics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/staltz%2Fcallbag-basics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/staltz%2Fcallbag-basics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/staltz","download_url":"https://codeload.github.com/staltz/callbag-basics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248790529,"owners_count":21162029,"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":["callbacks","callbag","iterables","observables","reactive"],"created_at":"2024-07-30T17:01:14.699Z","updated_at":"2025-04-13T22:30:25.109Z","avatar_url":"https://github.com/staltz.png","language":"JavaScript","funding_links":["https://patreon.com/andrestaltz"],"categories":["JavaScript","Table Contents","Functional Programming","📦 Legacy \u0026 Inactive Projects","State Managers"],"sub_categories":["Misc","Reactive Programming"],"readme":"# Callbag basics 👜\n\nBasic callbag factories and operators to get started with. [Callbag](https://github.com/callbag/callbag) is just a spec, but `callbag-basics` is a real library you can use.\n\n**Highlights:**\n\n- Supports reactive stream programming\n- Supports iterable programming (also!)\n- Same operator works for both of the above\n- Tiny! Weighs just [7kB](https://github.com/staltz/callbag-basics/tree/master/dist)\n- Fast! [Faster than](https://github.com/staltz/callbag-basics/tree/master/perf) xstream and RxJS\n- Extensible: no core library! Everything is a utility function\n\nImagine a hybrid between an Observable and an (Async)Iterable, that's what callbags are all about. In addition, the internals are tiny because it's all done with a few simple callbacks, following the [callbag spec](https://github.com/callbag/callbag). As a result, it's tiny and fast.\n\n## Usage\n\n`npm install callbag-basics`\n\nImport operators and factories:\n\n```js\nconst {forEach, fromIter, map, filter, pipe} = require('callbag-basics');\n```\n\n## Try it online\n\n- [Observe Events](https://codesandbox.io/s/p5jwlp0x07)\n- [Flatten Promises](https://codesandbox.io/s/1o8ykm56o4)\n- [Flatten Events with Promises](https://codesandbox.io/s/m32m21v59x)\n\n### Reactive programming examples\n\nLog XY coordinates of click events on `\u003cbutton\u003e` elements:\n\n```js\nconst {forEach, fromEvent, map, filter, pipe} = require('callbag-basics');\n\npipe(\n  fromEvent(document, 'click'),\n  filter(ev =\u003e ev.target.tagName === 'BUTTON'),\n  map(ev =\u003e ({x: ev.clientX, y: ev.clientY})),\n  forEach(coords =\u003e console.log(coords))\n);\n\n// {x: 110, y: 581}\n// {x: 295, y: 1128}\n// ...\n```\n\nPick the first 5 odd numbers from a clock that ticks every second, then start observing them:\n\n```js\nconst {forEach, interval, map, filter, take, pipe} = require('callbag-basics');\n\npipe(\n  interval(1000),\n  map(x =\u003e x + 1),\n  filter(x =\u003e x % 2),\n  take(5),\n  forEach(x =\u003e console.log(x))\n);\n\n// 1\n// 3\n// 5\n// 7\n// 9\n```\n\n### Iterable programming examples\n\nFrom a range of numbers, pick 5 of them and divide them by 4, then start pulling those one by one:\n\n```js\nconst {forEach, fromIter, take, map, pipe} = require('callbag-basics');\n\nfunction* range(from, to) {\n  let i = from;\n  while (i \u003c= to) {\n    yield i;\n    i++;\n  }\n}\n\npipe(\n  fromIter(range(40, 99)), // 40, 41, 42, 43, 44, 45, 46, ...\n  take(5), // 40, 41, 42, 43, 44\n  map(x =\u003e x / 4), // 10, 10.25, 10.5, 10.75, 11\n  forEach(x =\u003e console.log(x))\n);\n\n// 10\n// 10.25\n// 10.5\n// 10.75\n// 11\n```\n\n## API\n\nThe list below shows what's included.\n\n### Source factories\n\n- [fromObs](https://github.com/staltz/callbag-from-obs)\n- [fromIter](https://github.com/staltz/callbag-from-iter)\n- [fromEvent](https://github.com/staltz/callbag-from-event)\n- [fromPromise](https://github.com/staltz/callbag-from-promise)\n- [interval](https://github.com/staltz/callbag-interval)\n\n### Sink factories\n\n- [forEach](https://github.com/staltz/callbag-for-each)\n\n### Transformation operators\n\n- [map](https://github.com/staltz/callbag-map)\n- [scan](https://github.com/staltz/callbag-scan)\n- [flatten](https://github.com/staltz/callbag-flatten)\n\n### Filtering operators\n\n- [take](https://github.com/staltz/callbag-take)\n- [skip](https://github.com/staltz/callbag-skip)\n- [filter](https://github.com/staltz/callbag-filter)\n\n### Combination operators\n\n- [merge](https://github.com/staltz/callbag-merge)\n- [concat](https://github.com/staltz/callbag-concat)\n- [combine](https://github.com/staltz/callbag-combine)\n\n### Utilities\n\n- [share](https://github.com/staltz/callbag-share)\n- [pipe](https://github.com/staltz/callbag-pipe)\n\n### More\n\n- [*Check the Wiki*](https://github.com/callbag/callbag/wiki)\n\n## Terminology\n\n- **source**: a callbag that delivers data\n- **sink**: a callbag that receives data\n- **puller sink**: a sink that actively requests data from the source\n- **pullable source**: a source that delivers data only on demand (on receiving a request)\n- **listener sink**: a sink that passively receives data from the source\n- **listenable source**: source which sends data to the sink without waiting for requests\n- **operator**: a callbag based on another callbag which applies some operation\n\n## Contributing\n\n**The Callbag philosophy is: build it yourself.** :)\nYou can send pull requests, but even better, don't depend on the repo owner accepting it. Just fork the project, customize it as you wish, and publish your fork on npm. As long as it follows the callbag spec, everything will be interoperable! :)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstaltz%2Fcallbag-basics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstaltz%2Fcallbag-basics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstaltz%2Fcallbag-basics/lists"}