All Projects → teohhanhui → callbag-rs

teohhanhui / callbag-rs

Licence: other
Rust implementation of the callbag spec for reactive/iterable programming

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to callbag-rs

Kefir
A Reactive Programming library for JavaScript
Stars: ✭ 1,769 (+6976%)
Mutual labels:  reactive, stream, observable, frp
Marble
Marble.js - functional reactive Node.js framework for building server-side applications, based on TypeScript and RxJS.
Stars: ✭ 1,947 (+7688%)
Mutual labels:  reactive, stream, observable
Rxviz
Rx Visualizer - Animated playground for Rx Observables
Stars: ✭ 1,471 (+5784%)
Mutual labels:  reactive, stream, observable
reactive-rs
Streams and broadcasts: functional reactive programming in Rust.
Stars: ✭ 28 (+12%)
Mutual labels:  reactive, stream, frp
reflex-native
Framework for writing fully native apps using Reflex, a Functional Reactive Programming library for Haskell.
Stars: ✭ 40 (+60%)
Mutual labels:  reactive, frp
rxact
Rxact is an observable application management for Javascript app
Stars: ✭ 21 (-16%)
Mutual labels:  stream, observable
reactify
The first and only true Functional Reactive Programming framework for Scala.
Stars: ✭ 77 (+208%)
Mutual labels:  reactive, frp
rxjava2-http
Transmit RxJava2 Flowable over http with non-blocking backpressure
Stars: ✭ 19 (-24%)
Mutual labels:  reactive, stream
react-callbag-listener
👂 A React render-prop component that listens to values emitted by callbags
Stars: ✭ 21 (-16%)
Mutual labels:  observable, callbag
go-callbag
golang implementation of Callbag
Stars: ✭ 19 (-24%)
Mutual labels:  stream, callbag
immerx-state
Reactive, fractal and no-nonsense state management with Immer
Stars: ✭ 19 (-24%)
Mutual labels:  reactive, observable
mobius-gui
🎨 Reactive & Stream & Driver based UI framework build on Mobius Utils, equipped with neumorphism-derived & utility-first styles.
Stars: ✭ 43 (+72%)
Mutual labels:  reactive, stream
purescript-outwatch
A functional and reactive UI framework based on Rx and VirtualDom
Stars: ✭ 33 (+32%)
Mutual labels:  reactive, frp
mutable
State containers with dirty checking and more
Stars: ✭ 32 (+28%)
Mutual labels:  observable, frp
callbag-subscribe
A callbag sink (listener) that connects an Observer a-la RxJS. 👜
Stars: ✭ 17 (-32%)
Mutual labels:  reactive, callbag
purescript-pop
😃 A functional reactive programming (FRP) demo created with PureScript events and behaviors.
Stars: ✭ 33 (+32%)
Mutual labels:  reactive, frp
observable ish
Observable state and events for browser and Flutter.
Stars: ✭ 26 (+4%)
Mutual labels:  reactive, observable
reflex-dom-semui
A reflex-dom API for Semantic UI components
Stars: ✭ 22 (-12%)
Mutual labels:  reactive, frp
reflex-dom-ace
Reflex wrapper for the ACE editor
Stars: ✭ 12 (-52%)
Mutual labels:  reactive, frp
realar
5 kB Advanced state manager for React
Stars: ✭ 41 (+64%)
Mutual labels:  reactive, observable

callbag-rs

Rust implementation of the callbag spec for reactive/iterable programming.

Basic callbag factories and operators to get started with.

Highlights:

  • Supports reactive stream programming
  • Supports iterable programming (also!)
  • Same operator works for both of the above
  • Extensible

Imagine a hybrid between an Observable and an (Async)Iterable, that's what callbags are all about. It's all done with a few simple callbacks, following the callbag spec.

CI Crates.io Documentation MIT OR Apache-2.0 licensed

Examples

Reactive programming examples

Pick the first 5 odd numbers from a clock that ticks every second, then start observing them:

use async_nursery::Nursery;
use crossbeam_queue::SegQueue;
use std::{sync::Arc, time::Duration};

use callbag::{filter, for_each, interval, map, pipe, take};

let (nursery, nursery_out) = Nursery::new(async_executors::AsyncStd);

let actual = Arc::new(SegQueue::new());

pipe!(
    interval(Duration::from_millis(1_000), nursery.clone()),
    map(|x| x + 1),
    filter(|x| x % 2 == 1),
    take(5),
    for_each({
        let actual = Arc::clone(&actual);
        move |x| {
            println!("{x}");
            actual.push(x);
        }
    }),
);

drop(nursery);
async_std::task::block_on(nursery_out);

assert_eq!(
    &{
        let mut v = vec![];
        while let Some(x) = actual.pop() {
            v.push(x);
        }
        v
    }[..],
    [1, 3, 5, 7, 9]
);

Iterable programming examples

From a range of numbers, pick 5 of them and divide them by 4, then start pulling those one by one:

use crossbeam_queue::SegQueue;
use std::sync::Arc;

use callbag::{for_each, from_iter, map, pipe, take};

#[derive(Clone)]
struct Range {
    i: usize,
    to: usize,
}

impl Range {
    fn new(from: usize, to: usize) -> Self {
        Range { i: from, to }
    }
}

impl Iterator for Range {
    type Item = usize;

    fn next(&mut self) -> Option<Self::Item> {
        let i = self.i;
        if i <= self.to {
            self.i += 1;
            Some(i)
        } else {
            None
        }
    }
}

let actual = Arc::new(SegQueue::new());

pipe!(
    from_iter(Range::new(40, 99)),
    take(5),
    map(|x| x as f64 / 4.0),
    for_each({
        let actual = Arc::clone(&actual);
        move |x| {
            println!("{x}");
            actual.push(x);
        }
    }),
);

assert_eq!(
    &{
        let mut v = vec![];
        while let Some(x) = actual.pop() {
            v.push(x);
        }
        v
    }[..],
    [10.0, 10.25, 10.5, 10.75, 11.0]
);

Ok::<(), Box<dyn std::error::Error>>(())

API

The list below shows what's included.

Source factories

Sink factories

Transformation operators

Filtering operators

Combination operators

Utilities

Terminology

  • source: a callbag that delivers data
  • sink: a callbag that receives data
  • puller sink: a sink that actively requests data from the source
  • pullable source: a source that delivers data only on demand (on receiving a request)
  • listener sink: a sink that passively receives data from the source
  • listenable source: source which sends data to the sink without waiting for requests
  • operator: a callbag based on another callbag which applies some operation

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Acknowledgements

Thanks to André Staltz (@staltz) for creating the callbag spec.

This library is a port of https://github.com/staltz/callbag-basics. Some inspiration was taken from https://github.com/f5io/callbag.rs.

Many thanks to the awesome folks on the Rust Users Forum for their help, especially:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].