Re:Idiomatic Monads in Rust
by empath75 on Thursday April 04, 2019 @08:37PM
(#19578539)
Implementing monads will be convoluted, using them is relatively easy. It wouldn’t change any of the existing code, but it would allow you to write a function like this:
fn double_inner<M: Monad<u64>>(m: M) -> M {
m.bind(|x| M::unit(x * 2))
}
Which takes anything wrapping an integer and doubles it, whether it’s an option or result or iterator.
fn double_inner<M: Monad<u64>>(m: M) -> M { m.bind(|x| M::unit(x * 2)) }
Which takes anything wrapping an integer and doubles it, whether it’s an option or result or iterator.