From 12231ac249522cb718009e04aa0f9c422416e1d9 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Tue, 24 Oct 2017 23:58:56 +0700 Subject: [PATCH] =?UTF-8?q?add=20=E2=80=9CFree=20syntactic=20sugar?= =?UTF-8?q?=E2=80=9D=20section=20to=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9207d6d..1b0cefa 100644 --- a/README.md +++ b/README.md @@ -111,13 +111,13 @@ namespace kari { --- -## `kari::curry(F&& f, Args&&... args)` +### `kari::curry(F&& f, Args&&... args)` Returns a curried function **`f`** or copy the function result with **`args`** arguments. --- -## `kari::curryV(F&& f, Args&&... args)` +### `kari::curryV(F&& f, Args&&... args)` Allows carrying variadic functions. @@ -132,7 +132,7 @@ c2(); // output: 37 + 5 = 42 --- -## `kari::curryN(F&& f, Args&&... args)` +### `kari::curryN(F&& f, Args&&... args)` Allows carrying variadic functions for **`N`** arguments. @@ -145,7 +145,7 @@ std::cout << buffer << std::endl; // output: 37 + 5 = 42 --- -## `kari::is_curried, kari::is_curried_v` +### `kari::is_curried, kari::is_curried_v` Checks whether F is a curried function type. @@ -170,7 +170,7 @@ std::cout --- -## `kari::curry_t::operator()(As&&... as)` +### `kari::curry_t::operator()(As&&... as)` Calling operator of curried function for partial application or full application. Returns a new curried function with added new arguments or copy of the function result. @@ -187,4 +187,34 @@ auto rr = c2(2, 5); // function call - foo(15,20,2,5) std::cout << rr << std::endl; ``` ---- \ No newline at end of file +--- + +## Free syntactic sugar + +### Section of operators + +```cpp +using namespace kari::underscore; +std::vector v{1,2,3,4}; + +// result: 10 +std::accumulate(v.begin(), v.end(), 0, _+_); + +// v = 2, 3, 6, 8 +std::transform(v.begin(), v.end(), v.begin(), _*2); + +// v = -2,-3,-6,-8 +std::transform(v.begin(), v.end(), v.begin(), -_); +``` + +### Function composition + +```cpp +using namespace kari::underscore; + +auto r0 = (_*2) * (_+2) * 4; // (4 + 2) * 2 = 12 +auto r1 = 4 * (_*2) * (_+2); // (4 * 2 + 2) = 10 + +// output: 12,10 +std::cout << r0, << "," << r1 << std::endl; +``` \ No newline at end of file