#pragma once #include #include #include namespace Void::Pipeline { // ── curry ───────────────────────────────────────────────────────────────────── // Transforms a multi-argument callable into a chain of single-argument calls. // // auto add = curry([](int a, int b) { return a + b; }); // auto add5 = add(5); // partially applied — returns another callable // int sum = add5(3); // = 8, all args collected → invoked namespace Detail { template struct Curried { F fn; std::tuple args; template constexpr auto operator()(Arg&& arg) && { auto new_args = std::tuple_cat(std::move(args), std::tuple>{std::forward(arg)}); using NewCurried = Curried>; if constexpr (std::is_invocable_v>) { return std::apply(fn, std::move(new_args)); } else { return NewCurried{std::move(fn), std::move(new_args)}; } } template constexpr auto operator()(Arg&& arg) const & { auto new_args = std::tuple_cat(args, std::tuple>{std::forward(arg)}); using NewCurried = Curried>; if constexpr (std::is_invocable_v>) { return std::apply(fn, std::move(new_args)); } else { return NewCurried{std::move(fn), std::move(new_args)}; } } }; } // namespace Detail template [[nodiscard]] constexpr auto curry(F&& fn) { return Detail::Curried>{std::forward(fn), {}}; } } // namespace Void::Pipeline