{"id":21286166,"url":"https://github.com/teohhanhui/callbag-rs","last_synced_at":"2025-07-11T11:32:41.796Z","repository":{"id":40394228,"uuid":"424268251","full_name":"teohhanhui/callbag-rs","owner":"teohhanhui","description":"Rust implementation of the callbag spec for reactive/iterable programming","archived":false,"fork":false,"pushed_at":"2022-05-11T14:03:39.000Z","size":246,"stargazers_count":30,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-26T03:17:23.287Z","etag":null,"topics":["callbag","frp","iterable","observable","reactive","rust","stream"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/teohhanhui.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-03T14:58:50.000Z","updated_at":"2023-08-04T09:57:59.000Z","dependencies_parsed_at":"2022-08-09T19:10:38.131Z","dependency_job_id":null,"html_url":"https://github.com/teohhanhui/callbag-rs","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/teohhanhui/callbag-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teohhanhui%2Fcallbag-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teohhanhui%2Fcallbag-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teohhanhui%2Fcallbag-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teohhanhui%2Fcallbag-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teohhanhui","download_url":"https://codeload.github.com/teohhanhui/callbag-rs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teohhanhui%2Fcallbag-rs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264795402,"owners_count":23665231,"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":["callbag","frp","iterable","observable","reactive","rust","stream"],"created_at":"2024-11-21T11:27:49.520Z","updated_at":"2025-07-11T11:32:40.741Z","avatar_url":"https://github.com/teohhanhui.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"#   callbag-rs\n\nRust implementation of the [callbag spec][callbag-spec] for reactive/iterable programming.\n\nBasic [callbag][callbag-spec] factories and operators to get started with.\n\n**Highlights:**\n\n- Supports reactive stream programming\n- Supports iterable programming (also!)\n- Same operator works for both of the above\n- Extensible\n\nImagine a hybrid between an [Observable][tc39-observable] and an [(Async)Iterable][tc39-async-iteration], that's what\ncallbags are all about. It's all done with a few simple callbacks, following the [callbag spec][callbag-spec].\n\n[![CI][ci-badge]][ci-url]\n[![Crates.io][crates-badge]][crates-url]\n[![Documentation][docs-badge]][docs-url]\n[![MIT OR Apache-2.0 licensed][license-badge]][license-url]\n\n##  Examples\n\n### Reactive programming examples\n\nPick the first 5 odd numbers from a clock that ticks every second, then start observing them:\n\n```rust\nuse async_nursery::Nursery;\nuse crossbeam_queue::SegQueue;\nuse std::{sync::Arc, time::Duration};\n\nuse callbag::{filter, for_each, interval, map, pipe, take};\n\nlet (nursery, nursery_out) = Nursery::new(async_executors::AsyncStd);\n\nlet actual = Arc::new(SegQueue::new());\n\npipe!(\n    interval(Duration::from_millis(1_000), nursery.clone()),\n    map(|x| x + 1),\n    filter(|x| x % 2 == 1),\n    take(5),\n    for_each({\n        let actual = Arc::clone(\u0026actual);\n        move |x| {\n            println!(\"{x}\");\n            actual.push(x);\n        }\n    }),\n);\n\ndrop(nursery);\nasync_std::task::block_on(nursery_out);\n\nassert_eq!(\n    \u0026{\n        let mut v = vec![];\n        while let Some(x) = actual.pop() {\n            v.push(x);\n        }\n        v\n    }[..],\n    [1, 3, 5, 7, 9]\n);\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```rust\nuse crossbeam_queue::SegQueue;\nuse std::sync::Arc;\n\nuse callbag::{for_each, from_iter, map, pipe, take};\n\n#[derive(Clone)]\nstruct Range {\n    i: usize,\n    to: usize,\n}\n\nimpl Range {\n    fn new(from: usize, to: usize) -\u003e Self {\n        Range { i: from, to }\n    }\n}\n\nimpl Iterator for Range {\n    type Item = usize;\n\n    fn next(\u0026mut self) -\u003e Option\u003cSelf::Item\u003e {\n        let i = self.i;\n        if i \u003c= self.to {\n            self.i += 1;\n            Some(i)\n        } else {\n            None\n        }\n    }\n}\n\nlet actual = Arc::new(SegQueue::new());\n\npipe!(\n    from_iter(Range::new(40, 99)),\n    take(5),\n    map(|x| x as f64 / 4.0),\n    for_each({\n        let actual = Arc::clone(\u0026actual);\n        move |x| {\n            println!(\"{x}\");\n            actual.push(x);\n        }\n    }),\n);\n\nassert_eq!(\n    \u0026{\n        let mut v = vec![];\n        while let Some(x) = actual.pop() {\n            v.push(x);\n        }\n        v\n    }[..],\n    [10.0, 10.25, 10.5, 10.75, 11.0]\n);\n\nOk::\u003c(), Box\u003cdyn std::error::Error\u003e\u003e(())\n```\n\n##  API\n\nThe list below shows what's included.\n\n### Source factories\n\n- [from_iter](https://docs.rs/callbag/latest/callbag/fn.from_iter.html)\n- [interval](https://docs.rs/callbag/latest/callbag/fn.interval.html)\n\n### Sink factories\n\n- [for_each](https://docs.rs/callbag/latest/callbag/fn.for_each.html)\n\n### Transformation operators\n\n- [map](https://docs.rs/callbag/latest/callbag/fn.map.html)\n- [scan](https://docs.rs/callbag/latest/callbag/fn.scan.html)\n- [flatten](https://docs.rs/callbag/latest/callbag/fn.flatten.html)\n\n### Filtering operators\n\n- [take](https://docs.rs/callbag/latest/callbag/fn.take.html)\n- [skip](https://docs.rs/callbag/latest/callbag/fn.skip.html)\n- [filter](https://docs.rs/callbag/latest/callbag/fn.filter.html)\n\n### Combination operators\n\n- [merge!](https://docs.rs/callbag/latest/callbag/macro.merge.html)\n- [concat!](https://docs.rs/callbag/latest/callbag/macro.concat.html)\n- [combine!](https://docs.rs/callbag/latest/callbag/macro.combine.html)\n\n### Utilities\n\n- [share](https://docs.rs/callbag/latest/callbag/fn.share.html)\n- [pipe!](https://docs.rs/callbag/latest/callbag/macro.pipe.html)\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##  License\n\nLicensed under either of\n\n * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT)\n\nat your option.\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as\ndefined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n##  Acknowledgements\n\nThanks to André Staltz ([@staltz](https://github.com/staltz)) for creating the [callbag spec][callbag-spec].\n\nThis library is a port of \u003chttps://github.com/staltz/callbag-basics\u003e. Some inspiration was taken from\n\u003chttps://github.com/f5io/callbag.rs\u003e.\n\nMany thanks to the awesome folks on the [Rust Users Forum](https://users.rust-lang.org/) for their help, especially:\n- Alice Ryhl ([alice](https://users.rust-lang.org/u/alice))\n- Jessa ([jessa0](https://users.rust-lang.org/u/jessa0))\n\n[callbag-spec]: https://github.com/callbag/callbag\n[ci-badge]: https://github.com/teohhanhui/callbag-rs/actions/workflows/ci.yml/badge.svg\n[ci-url]: https://github.com/teohhanhui/callbag-rs/actions/workflows/ci.yml\n[crates-badge]: https://img.shields.io/crates/v/callbag\n[crates-url]: https://crates.io/crates/callbag\n[docs-badge]: https://img.shields.io/docsrs/callbag\n[docs-url]: https://docs.rs/callbag\n[license-badge]: https://img.shields.io/crates/l/callbag\n[license-url]: https://github.com/teohhanhui/callbag-rs#license\n[tc39-async-iteration]: https://github.com/tc39/proposal-async-iteration\n[tc39-observable]: https://github.com/tc39/proposal-observable\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteohhanhui%2Fcallbag-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteohhanhui%2Fcallbag-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteohhanhui%2Fcallbag-rs/lists"}