To express the type contracts of (left/right) flatMap and map, we should introduce meta functions for SFINAE.
template<class L, class R>
auto ensureEither( Either<L,R> const& e) - > decltype( e ) {
return e;
}
template<class L, class R>
auto ensureEither( Either<L,R> const& e, L, R ) - > decltype( e ) {
return e;
}
template<class L, class R>
auto ensureEitherLeft( Either<L,R> const& e, L) - > decltype( e ) {
return e;
}
template<class L, class R>
auto ensureEitherRight( Either<L,R> const& e, R) - > decltype( e ) {
return e;
}
This could be used to express the contracts of map:
To express the type contracts of (left/right) flatMap and map, we should introduce meta functions for SFINAE.
This could be used to express the contracts of map: