Manu343726 / snail

Continuation-ready container algorithms from STL algorithms
MIT License
60 stars 4 forks source link

Category group for lazy algorithms in a pure CPS style #5

Open Manu343726 opened 9 years ago

Manu343726 commented 9 years ago

Joaquin M Lopez Muñoz pointed out on a reddit thread:

In fact, the design pattern you propose would be closer to a continuation-like monad if the lib allowed for algorithm chaining with deferred execution:

auto v=move()|sort([](...){...})|...;
std::cout<<v({1,2,3});

which would enable interesting (or fun, at least) applications.

I think this is an interesting feature that deserves consideration. Despite the actual categories feel more natural for me (They operate on the input container directly), the deferred version operates much better on large data sets.

I propose a new group of algorithm categories snail::categories::lazy_XXXX implementing CPS.

It's possible to write a function to translate the current Container -> Container algorithms into it's CPS version directly?

stefanloerwald commented 9 years ago

You can always write

Container foo(Container v) { return std::move(v) | sort(...) | for_each(...) | map(...); }