# ChainCall **Repository Path**: brainburster/ChainCall ## Basic Information - **Project Name**: ChainCall - **Description**: c++11, 重载>>操作符,实现函数组合与链式调用,用于pointfree风格编程 - **Primary Language**: Unknown - **License**: Unlicense - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-01-21 - **Last Updated**: 2022-06-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ChainCall ## Usage ```cpp #include "chaincall.hpp" ... //chain auto v1 = chaincall::chain() >> [] { return 42; } >> add_1 >> power_2 >> div_2; auto v2 = chaincall::chain(2) >> add_1 >> power_2 >> div_2; auto v3 = chaincall::chain(1, 2) >> [](int a, int b) { return a + b; } >> power_2 >> div_2; auto v4 = chaincall::chain() >> [] { return make_tuple(3, 7); } >> [](int a, int b) { return a * b; } >> power_2 >> div_2; cout << v1.value << endl; //(42+1)**2/2 = 924 cout << v2.value << endl; //(2+1)**2/2 = 4 cout << v3.value << endl; //(1+2)**2/2 = 4 cout << v4.value << endl; //(3*7)**2/2 = 220 //pipe auto composed_func1 = chaincall::pipe([](int a, int b) { return a * b; }, power_2, div_2); auto composed_func2 = chaincall::pipe() << add << power_2 << div_2; cout << composed_func1(2, 7).value << endl; //(2*7)**2/2 = 98 cout << composed_func2(2, 7).value << endl; //(2+7)**2/2 = 40 struct Person { std::string m_name; int m_age; void greeting() { cout<< "Hello, My name is " << m_name << ", I am " << m_age << " years old" <> add >>set_age >> greeting; chain(std::string{"Xiao Lee"}) >> set_name >> greeting; //pipe auto add_setAge_greeting = pipe() >> add >> set_age >> greeting; auto setName_greeting = pipe() >> set_name >> greeting; add_setAge_greeting(22,1); setName_greeting(std::string{"Lee Hua"}); ... ``` ## Output ``` 924 4 4 220 98 40 Hello, My name is Lee Hua, I am 19 years old Hello, My name is Xiao Lee, I am 19 years old Hello, My name is Xiao Lee, I am 23 years old Hello, My name is Lee Hua, I am 23 years old ```