id_effect 0.9.0

Effect<A, E, R>: lazy Send effects over a typed capability list, run on a fiber runtime (Tokio executor), with layers, streams, schedules and coordination
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! Ex 012 — `catch` recovers from a typed failure.
use id_effect::Exit;
use id_effect::{Effect, effect, succeed};

fn parse_i32(raw: &'static str) -> Effect<i32, &'static str> {
  effect!({ raw.parse::<i32>().map_err(|_| "parse_failed")? })
}

fn main() {
  let program: Effect<i32, &'static str> = effect!({
    let v = ~parse_i32("x").catch(|_| succeed(0));
    v + 42
  });
  assert_eq!(program.block_on(), Exit::succeed(42));
  println!("012_catch ok");
}