// // fluent.hpp // stream // // Created by Sam Jaffe on 1/28/17. // #pragma once #include "../streams.hpp" #include namespace stream { template struct map { template explicit map(F&& f) : func(f) {} std::function func; }; template struct flatmap { template explicit flatmap(F&& f) : func(f) {} std::function func; }; template struct filter { template explicit filter(F&& f) : pred(f) {} std::function pred; }; template struct fold_left { template explicit fold_left(F&& f, L const & i = L()) : init(i), fold(f) {} L init; std::function fold; }; } namespace stream { namespace detail { template stream_base operator|(stream_base const&s, ::stream::map::type, R>&& f) { return s.map(f.func); } template stream_base operator|(stream_base const&s, ::stream::flatmap::type, C>&& f) { return s.flatmap(f.func); } template stream_base operator|(stream_base const&s, ::stream::filter::type>&& f) { return s.filter(f.pred); } template L operator >(stream_base const &s, ::stream::fold_left::type> && f) { return std::accumulate(s.begin(), s.end(), f.init, f.fold); } template C & operator >(stream_base const & s, C & c) { s.collect(c); return c; } } }