A structure for suspended closure composition in Rust
rust
let mut fm: Morphism<uint, uint> = Morphism::new();
for _ in range(0u, 100000u) {
fm = fm.push(|:x| x + 42u);
}
let mut gm: Morphism<uint, uint> = Morphism::new();
for _ in range(0u, 100000u) {
gm = gm.push(|:x| x - 42u);
}
let gm = gm
.push(|:x| Some(x))
.push(|:x| x.map(|y| y + 42u))
.push(|:x| x.map(|y| y.to_string()));
assert_eq!(fm.then(gm).run(0u), Some(String::from_str("42")));
See the API documentation here.
You can install both with the following:
$ curl -s https://static.rust-lang.org/rustup.sh | sudo sh
See Installing Rust for further details.
$ cargo build ## build library and binary
$ cargo test ## run tests in ./tests
$ cargo bench ## run benchmarks in ./benches
There is an IRC channel on freenode (chat.freenode.net) at #epsilonz.