"Pipe" operator for chaining operations
firedaemon-cto opened this issue · 1 comments
firedaemon-cto commented
I am not sure if you have considered this possibility: I find it much more generic to provide "free functions" to decouple the extension of functionality from the core of a class than the intrusive way via member methods.
This way, the standard std::epected
doesn't have to be replaced or updated by a proposal, and its use can be made even more useful.
The "pipe" operator|()
can be used as a convenient way to concatenate things, and the syntax looks and feels as natural as the "dot" operator:
tl::expected<image,fail_reason> get_cute_cat (const image& img) {
return crop_to_cat(img)
| and_then(add_bow_tie)
| and_then(make_eyes_sparkle)
| map(make_smaller)
| map(add_rainbow);
}
This would also apply to your proposal for monadic operations for std::optional
.
firedaemon-cto commented
Oh, I see now that free functions were taken into consideration.