functype-io 0.1.1

Lazy, composable IO effect type for functype
Documentation

functype-io

Lazy, composable IO effect type for Rust.

Part of the functype library.

IO<A>

A deferred computation that produces a value of type A or fails with an error. Nothing executes until .run() is called.

use functype_io::IO;

let io = IO::effect(|| {
    println!("side effect!");
    42
}).map(|x| x * 2);

// Nothing printed yet
let result = io.run().unwrap(); // prints "side effect!", returns 84

Features

  • Constructorssucceed, fail, effect, effect_result, from_result, from_option, from_either
  • Combinatorsmap, flat_map, zip, zip_with, then, tap
  • Error handlingmap_error, catch, or_else, either(), retry
  • Resource safetybracket (acquire/use/release), ensuring (finalizer)
  • Async interopfrom_future, to_future
  • Do-notation — Works with fdo! macro via and_then/map

Usage

[dependencies]
functype-io = "0.1"
use functype_io::IO;
use functype_core::fdo;

let result = fdo! {
    x <- IO::succeed(10);
    y <- IO::succeed(20);
    yield x + y
};
assert_eq!(result.run().unwrap(), 30);

License

MIT OR Apache-2.0