comp-rs
Pure-macro Do notation and List-comprehension for Option, Result and Iterator.
It provides syntax extensions to easily combind wrapper type (Option, Result and Iterator), which seems like
for-comprehension in scala or Do notation in haskell.
Documentation
Usage
First, add the following to your Cargo.toml:
[]
= "0.1"
Next, add this to your crate root:
extern crate comp;
Example
comp-rs delivers three macros : option!, result! and iter!,
transforming the arrow(<-) statements into FP bind (flat_map).
Iterator
extern crate comp;
let iter = iter! ;
for x in iter
// Print (0, 'a') (0, 'b') (1, 'a') (1, 'b')
Option
extern crate comp;
let option = option! ;
assert_eq!;
Result
Unlike Iterator and Option, rust provides Question Mark syntax to combine Results.
Let's see how comp-rs makes it more explicit and expressive.
Native way
extern crate comp;
use File;
use io;
use *;
// try!() macro must be wrap into a function
Question mark
extern crate comp;
use File;
use io;
use *;
// '?' mark must be wrap into a function
result! way
extern crate comp;
use File;
use io;
use *;
let content: Result = result! ;
Contribution
All kinds of contribution are welcome.
- Issue Feel free to open an issue when you find typos, bugs, or have any question.
- Pull requests. Better implementation, more tests, more documents and typo fixes are all welcome.
License
Licensed under MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)