[][src]Macro monadic::monadic

macro_rules! monadic {
    (let $v:ident = $e:expr ; $($rest:tt)*) => { ... };
    (guard $pred:expr ; $($rest:tt)*) => { ... };
    (_ <- $monad:expr ; $($rest:tt)* ) => { ... };
    ($v:ident <- $monad:expr ; $($rest:tt)* ) => { ... };
    (&$v:ident <- $monad:expr ; $($rest:tt)* ) => { ... };
    ($monad:expr                            ) => { ... };
}

converting monadic blocs of IntoIterator's as monads à la Haskell

You can use:

  • Option::pure( return_expresion) to return an expression value
  • v <- monadic_expression to use the monad result
  • _ <- monadic_expression to ignore the monad result
  • let z = expression to combine monad results
  • guard boolean_expression to filter results

it uses into_iter().flat_map instead of the defined bind for wider applicability since the latter requires the Sized constraint

There are transitive implementation relations for some structures to be instances of IntoIterator:

All iterators implement IntoIterator where into_iter() returns the self iterator structure as documented

Some structures e.g. Range implement a supertrait of Iterator, so they are IntoIterator instances, but they are not recognized as instances of the defined Bind as supertrait of IntoIterator and its implementation for all IntoIterators, so the macro doesn't use the defined bind() but into_iter().flatmap()

Iterator and IntoIterator trait imports are predefined