#frp #reactive #event #stream #signal

frappe

Functional Reactive Programming library for Rust

12 releases

0.4.7 Jun 10, 2020
0.4.6 Aug 23, 2019
0.4.5 Mar 14, 2019
0.4.4 Jan 25, 2019
0.1.0 Mar 19, 2017

#815 in Asynchronous

Download history 8/week @ 2022-06-10 11/week @ 2022-06-17 11/week @ 2022-06-24 18/week @ 2022-07-01 18/week @ 2022-07-08 30/week @ 2022-07-15 27/week @ 2022-07-22 34/week @ 2022-07-29 30/week @ 2022-08-05 12/week @ 2022-08-12 23/week @ 2022-08-19 15/week @ 2022-08-26 19/week @ 2022-09-02 52/week @ 2022-09-09 12/week @ 2022-09-16 12/week @ 2022-09-23

95 downloads per month
Used in 2 crates

MIT license

68KB
1.5K SLoC

frappe - FRP library for Rust

Build Status crates.io Documentation

Frappe is a concurrent Event-Driven FRP library. It aims to provide a simple, efficient and Rust-idiomatic way to write interactive applications in a declarative way.

Events are processed in streams, and they can be accumulated and read using signals. Also stream events can be turned into futures using the Stream::next method, so you can listen to them via async/await.

Usage

use frappe::Sink;

fn main() {
    // values are sent from a sink..
    let sink = Sink::new();
    // ..into a stream chain
    let stream = sink.stream().inspect(|a| println!("--sent: {}", a));

    // `hold` creates a Signal that stores the last value sent to the stream
    let last = stream.hold(0);

    // stream callbacks receive a MaybeOwned<T> argument, so we need to deref the value
    let sum = stream.fold(0, |acc, n| acc + *n);

    let half_even = stream
        // the methods filter, map, fold are analogous to Iterator operations
        .filter(|n| n % 2 == 0)
        .map(|n| *n / 2)
        .fold(Vec::new(), |mut vec, n| {
            vec.push(*n);
            vec
        }) // note: .collect::<Vec<_>>() does the same
        .map(|v| format!("{:?}", v));

    // we can send individual values
    sink.send(6);
    sink.send(42);
    sink.send(-1);
    // or multiple ones at once
    sink.feed(10..15);

    // `sample` gets a copy of the value stored in the signal
    println!("last: {}", last.sample());
    // printing a signal samples it
    println!("sum: {}", sum);
    println!("half_even: {}", half_even);
}

You can also check the frappe-gtk examples for more complex usage examples on GUI applications.

Dependencies

~1.5MB
~24K SLoC