#frp #reactive #event #stream #signal

frappe

Functional Reactive Programming library for Rust

10 releases

✓ Uses Rust 2018 edition

0.4.5 Mar 14, 2019
0.4.4 Jan 25, 2019
0.3.1 Nov 2, 2017
0.3.0 Oct 12, 2017
0.1.0 Mar 19, 2017

#39 in Asynchronous

Download history 22/week @ 2019-01-12 35/week @ 2019-01-19 9/week @ 2019-01-26 5/week @ 2019-02-02 3/week @ 2019-02-09 2/week @ 2019-02-16 8/week @ 2019-02-23 24/week @ 2019-03-02 35/week @ 2019-03-09 25/week @ 2019-03-16 124/week @ 2019-03-23 5/week @ 2019-03-30 17/week @ 2019-04-06 8/week @ 2019-04-13 11/week @ 2019-04-20

101 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.

Experimental support for futures has been added. To enable it, use a nightly compiler and enable the "nightly" crate feature.

Work in progress, so the API can change at any time.

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
~22K SLoC