Carboxyl is a library for functional reactive programming in Rust, a functional and composable approach to handle events in interactive applications. Read more in the docs…
Note that currently Rust nightly is required to use this crate!
Usage example
Here is a simple example of how you can use the primitives provided by Carboxyl. First of all, events can be sent into a sink. From a sink one can create a stream of events. Streams can also be filtered, mapped and merged. A signal is an abstraction of a value that may change over time. One can e.g. hold the last event from a stream in a signal.
use Sink;
let sink = new;
let stream = sink.stream;
let signal = stream.hold;
// The current value of the signal is initially 3
assert_eq!;
// When we fire an event, the signal get updated accordingly
sink.send;
assert_eq!;
One can also directly iterate over the stream instead of holding it in a signal:
let mut events = stream.events;
sink.send;
assert_eq!;
Streams and signals can be combined using various primitives. We can map a stream to another stream using a function:
let squares = stream.map.hold;
sink.send;
assert_eq!;
Or we can filter a stream to create a new one that only contains events that satisfy a certain predicate:
let negatives = stream.filter.hold;
// This won't arrive at the signal.
sink.send;
assert_eq!;
// But this will!
sink.send;
assert_eq!;
There are a couple of other primitives to compose streams and signals:
merge
two streams of events of the same type.- Make a
snapshot
of a signal, whenever a stream fires an event. lift!
an ordinary function to a function on signals.switch
between different signals using a signal containing a signal.
See the documentation for details.
License
Copyright 2014, 2015 Eduard Bopp.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License or GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.