I will note that it turns out that this is non-trivial to do in C++ and maintain good compatibility and expected behavior. Jonathan Boccara has actually implemented a pretty robust pipes library. It's header-only (yay!), but it does require C++14: github.com/joboccara/pipes
You will note that he chose to implement '>>=' as his pipe operator instead of '|', because it is highly discouraged to overload '|' in C++. I think this would be more accepted in Python, but even then there are valid concerns about order of operator execution.
If you want to nerd out about how Jonathan implemented his solution, he's got a series of articles about it on his blog, Fluent {C++}. Unlike some of his article series, it's not collected with links between them, as these are more development blog entries than concept entries, but here's part one about building composite reusable pipes: fluentcpp.com/2019/09/17/composite...
Thanks! Cross references are always a help. I get his newsletter, but somehow I forgot he had blogged about pipes. The brief implementation I showed in Python is also very limited; in order to allow fan-out/fan-in it'll need more code.
Indeed, operator| should do 'the expected'. In C++, >> has been around since the iostreams library, so we are more used to that. (if you dig deeper into the origin of this operator, you end up with bit shifting, too...).
I do notice a lot more enthousiasm when showing people "this is bash; look how similar that functional programming concept is", than "this is haskell; look how you do this in your world". That was my reason to do the wrong thing.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice coverage of how to pull this off.
I will note that it turns out that this is non-trivial to do in C++ and maintain good compatibility and expected behavior. Jonathan Boccara has actually implemented a pretty robust pipes library. It's header-only (yay!), but it does require C++14:
github.com/joboccara/pipes
You will note that he chose to implement '>>=' as his pipe operator instead of '|', because it is highly discouraged to overload '|' in C++. I think this would be more accepted in Python, but even then there are valid concerns about order of operator execution.
If you want to nerd out about how Jonathan implemented his solution, he's got a series of articles about it on his blog, Fluent {C++}. Unlike some of his article series, it's not collected with links between them, as these are more development blog entries than concept entries, but here's part one about building composite reusable pipes:
fluentcpp.com/2019/09/17/composite...
Thanks! Cross references are always a help. I get his newsletter, but somehow I forgot he had blogged about pipes. The brief implementation I showed in Python is also very limited; in order to allow fan-out/fan-in it'll need more code.
Indeed,
operator|
should do 'the expected'. In C++,>>
has been around since the iostreams library, so we are more used to that. (if you dig deeper into the origin of this operator, you end up with bit shifting, too...).The
>>=
refers nicely to Haskell's composition :).I do notice a lot more enthousiasm when showing people "this is bash; look how similar that functional programming concept is", than "this is haskell; look how you do this in your world". That was my reason to do the wrong thing.