id_effect 0.2.0

Effect<A, E, R> (sync + async), context/layers, pipe — interpreter-style, no bundled executor
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! Ex 077 — `TRef` read/write inside `commit`.
use id_effect::{TRef, commit, run_blocking};

fn main() {
  let stm = TRef::make(0_i32).flat_map(|cell| {
    let c1 = cell.clone();
    let c2 = cell.clone();
    cell
      .read_stm::<()>()
      .flat_map(move |v| {
        assert_eq!(v, 0);
        c1.write_stm::<()>(42)
      })
      .flat_map(move |_| c2.read_stm::<()>())
  });
  assert_eq!(run_blocking(commit(stm), ()), Ok(42));
  println!("077_stm_tref ok");
}