//! Ex 011 — `map_error` rewrites the failure type.
use effectful::{Effect, effect, run_blocking, succeed};

fn parse_i32(raw: &'static str) -> Effect<i32, &'static str, ()> {
  effect! {
    let v = bind* raw.parse::<i32>().map_err(|_| "parse_failed");
    v
  }
}

fn main() {
  let program = effect! {
    let raw = bind* succeed::<&'static str, &'static str, ()>("nope");
    let v = bind* parse_i32(raw).map_error(|_| "bad_input");
    v
  };
  assert_eq!(run_blocking(program, ()), Err("bad_input"));
  println!("011_map_error ok");
}
