diff --git a/Makefile b/Makefile index 7f16818..b1e7977 100644 --- a/Makefile +++ b/Makefile @@ -3,4 +3,4 @@ all: test test: - g++ -Iinclude --std=c++17 -o test tests/*.cpp \ No newline at end of file + g++ -g -Iinclude --std=c++17 -o test tests/*.cpp \ No newline at end of file diff --git a/include/combinations/compose.hpp b/include/combinations/compose.hpp index f3f826a..668f32a 100644 --- a/include/combinations/compose.hpp +++ b/include/combinations/compose.hpp @@ -2,18 +2,14 @@ #include "combinations/tuple.hpp" namespace cl{ - struct sigil_t{ - constexpr sigil_t(){} - }; - sigil_t sigil; template - class compose{ + class compose_t{ // f . next a f; - compose next; + compose_t next; public: - compose(a fn1, c ...oth) + compose_t(a fn1, c ...oth) : f{fn1} , next{oth...} {} @@ -25,11 +21,11 @@ namespace cl{ }; template - class compose{ + class compose_t{ // f . g a f; public: - compose(a fn1) + compose_t(a fn1) : f{fn1} {} template @@ -39,6 +35,12 @@ namespace cl{ }; + template + auto compose(a fn1, c ...oth) + { + return function(compose_t(fn1,oth...)); + } + template auto operator*(a fn1, b fn2) { diff --git a/include/combinations/curry.hpp b/include/combinations/curry.hpp index 5897bf3..254ced3 100644 --- a/include/combinations/curry.hpp +++ b/include/combinations/curry.hpp @@ -2,15 +2,15 @@ namespace cl { - template - class curry + template + class curry_t { - a param; fn call; + a param; public: - curry(a p, fn func) - : param{p} - , call{func} + curry_t(fn func, a p) + : call{func} + , param{p} {} template auto operator()(b ...Args){ diff --git a/include/combinations/function.hpp b/include/combinations/function.hpp index 32dc73b..786bb53 100644 --- a/include/combinations/function.hpp +++ b/include/combinations/function.hpp @@ -3,6 +3,9 @@ namespace cl { + template + auto curry(fn func, a p); + template class function{ a me; @@ -16,10 +19,16 @@ namespace cl } template auto operator()(cur arg){ - return curry(arg, me); + return curry(me, arg); } }; + template + auto curry(fn func, a p) + { + return function(curry_t(func, p)); + } + template ret invoke(invokable fn, Args ...args) { diff --git a/tests/compose.cpp b/tests/compose.cpp index 2a0b201..879b69c 100644 --- a/tests/compose.cpp +++ b/tests/compose.cpp @@ -8,8 +8,21 @@ struct test_001{ [](int a)->int{return a+2;}, [](int a)->int{return a*2;} ); - assert(fn(1)==6); + assert(fn(1)()==6); } }; -test_001 run_001; \ No newline at end of file +test_001 run_001; + +struct test_002{ + test_002() + { + using namespace cl; + auto fn = + [](int a)->int{return a+2;} + * [](int a)->int{return a*2;}; + assert(fn(2)()==8); + } +}; + +test_002 run_002; \ No newline at end of file diff --git a/tests/curry.cpp b/tests/curry.cpp new file mode 100644 index 0000000..f31123e --- /dev/null +++ b/tests/curry.cpp @@ -0,0 +1,26 @@ +#include "2CL.hpp" +#include + +struct test_003{ + test_003() + { + auto fn = cl::curry( + [](int a,int b)->int{return a+b;}, + 11 + ); + assert(fn(1)()==12); + } +}; + +test_003 run_003; + +struct test_004{ + test_004() + { + using namespace cl; + auto fn = function([](int a, int b)->int{return a+b;}); + assert(fn(2)(7)()==9); + } +}; + +test_004 run_004; \ No newline at end of file