use lubeck::common::state::State; use lubeck::prelude::*; type Rng = State<'static, usize, usize>; fn create_rng() -> Rng { Rng::new(|init_state| (init_state, init_state)).get() } fn roll(state: usize) -> Rng { // "random" ... lol const RANDOM_NUMBER: usize = 1239846; let new_state = state .wrapping_mul(RANDOM_NUMBER) .wrapping_add(RANDOM_NUMBER) % 1000; Rng::new(|init_state| (init_state, init_state)) .put(new_state) .get() } fn print(state: usize) -> usize { println!("The state is: {state}"); state } fn main() { let mut rng = create_rng(); // interesting fact: // stack overflows on my machine: // - debug: at 7_500 // - release: at 47_500 for _ in 0..100 { rng = rng.bind(roll).modify(print) } rng.run(2); }