// run-pass #![feature(try_trait_v2)] use std::ops::Try; fn monad_unit(x: ::Output) -> T { T::from_output(x) } fn monad_bind, T2: Try, R>( mx: T1, f: impl FnOnce(::Output) -> T2) -> T2 { let x = mx?; f(x) } fn main() { let mx: Option = monad_unit(1); let my = monad_bind(mx, |x| Some(x + 1)); let mz = monad_bind(my, |x| Some(-x)); assert_eq!(mz, Some(-2)); }