GithubHelp home page GithubHelp logo

bartop / tpl Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 0.0 564 KB

Template library for piping operations

License: GNU General Public License v3.0

C++ 99.65% CMake 0.35%
tpl cpp-library cpp cpp14 functional-programming functional

tpl's People

Contributors

bartop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tpl's Issues

Implement infinite enumerable

Enumerable 'infinite'

Input

Any value with copy constructor

Output

Enumerable returning the input value at every iteration.

Example

for(const auto &i : infinite(3))
    cout << i << ", "; //should print 3, 3, 3, 3 .........

Implement mapped_values operator

Operator mapped_values

Input

Associable enumerable.

Output

Enumerable to iterate through mapped values of given associable enumerable.

Example

const auto input = { std::make_pair(1, 2), std::make_pair(3, 4), std::make_pair(5, 6) };
const auto output = input | keys;
for(const auto &i : output)
    std::cout << i;
//output should be 2, 4, 6

Reduce copying of data even more

Currently some data (mostly in holders) is passed always by value. It is not very bad, but can be fixed using perfect forwarding.

Segregate the headers into subfolders

Currently there is quite a lot files in tpl directory. It should have few subdirectories like: sources, operators, sinks with corresponding headeres put inside them.

Add gcc 4.9 in Travis CI

gcc4.9 has theoretically all the features this library needs to work. We should try to add it to the matrix.

Implement generator enumerable

Enumerable generator

Input

Single argument function returning type convertible to its argument and initializing value of the same type as the function.

Output

Enumerable returning value "generated" by the function. Generator passes previous generated value to the function which builds up new value from it and returns it.

Example

for(const auto &i : generator([](const auto &i){ return i+i; }, 1))
    cout << i << ", "; //should print 1, 2, 4, 8, 16, ......

Add grouping headers for all directories

There should be operator.hpp for all headers in operator directory, sink.hpp for all in sink directory and so forth. Additionaly there should be a tpl.hpp including all of these.

Implement copy_to operator

Operator copy_to

Input

Enumerable and output iterator to copy into.

Output

No output. The outcome is that all elements from enumerable are copied into the output iterator,

Example

const auto input = { 1, 2, 3, 4, 5, 6 };
std::vector<int> output; 
input | copy_to(std::back_inserter(output));
//vector output should contain 1, 2, 3, 4, 5, 6

Implement drop operator

Operator drop

Input

Enumerable and unsigned number.

Output

Enumerable from the argument without given numer of elements from beginning.

Example

const auto input1 = { 1, 2, 3, 4, 5 };
const auto out = intput1 | drop(2);
//out should contain 3, 4, 5

Implement reverse operator

Operator reverse

Input

Enumerable.

Output

Enumerable with reversed order of elements.

Example

const auto input = { 1, 2, 3, 4, 5, 6 };
//sum example
const auto output = input | reverse;
//output should contain { 6, 5, 4, 3, 2, 1 };

Remarks

This feature depends on implementation of:

  • #8 Implementation of reverse iterators for enumerables

Implement zip operator

Operator zip

Input

Two enumerables

Output

Enumerable coresponding to "zipping" of two enumerables. For example from zip({1, 2}, {'a', 'b'}) -> { (1, 'a'), (2, 'b') }. In case zipped enumerables have different number of elements, the longer is truncated at the end.

Example

const auto input1 = { 1, 2, 3 };
const auto input2 = { 'a' , 'b', 'c', 'd' };
const auto zippped = zip(input1, input2);//zipped should contain { (1, 'a'), (2, 'b'), (3, 'c') }
//optionally input1 | zip(input2)

Add coverage control

Currently there is no code coverage control. Yet for the code to be tested well the coverage should be measured and controlled all the time.

Rename Container to Enumerable

For code to be more readable it should be used with internal naming - every Container in code should be raplaced with Enumerable.

Implement flatten operator

Operator flatten

Input

Enumerable of enumerables of generic type T.

Output

Enumerable containing all elements of the internal enumerables from input.

Example

const auto input = { (std::vector{1, 2}), (std::vector{3, 4, 5}), (std::vector{6}) };
const auto output = input | flatten;
for(const auto &i : output)
    std::cout << i;
//output should be 1, 2, 3, 4, 5, 6

Add AppVeyor CI

Currently only Travis is supported - Windows builds would be helpful.

Implement take operator

Operator take

Input

Enumerable and unsigned number.

Output

Enumerable containing given numer of elements from the beginning of the enumerable argument.

Example

const auto input1 = { 1, 2, 3, 4, 5 };
const auto out = intput1 | take(2);
//out should contain 1, 2

Refactor holders to factories

Currently many operations are using "holders" to construct operators later. There should be more OO solution used - instead of holders factories should be used with create method.

Implement "recursive" version of existing operators

"Deep" versions of algorithms would work for nested enumerables without breaking this nested hierarchy. For example:

const auto input = { (std::vector{1, 2}), (std::vector{3, 4, 5}), (std::vector{6}) };
const auto output1 = input | deep_filter([](const auto &i){ return i >=2; });
// output1 is now {{2}, {3, 4, 5}, {6}}

const auto output2 = input | deep_filter([](const auto &i){ return i < 6; });
// output2 is now {{1, 2}, {3, 4, 5}, {}}

I will gladly disscuss pros and cons of keeping the empty containers inside hierachy.

Our TODO list is:

  • transformed
  • sorted
  • filtered
  • flattened

Make sorted_sequence not cache data

Currently sorted_sequence caches the input only once. It can be a problem when dealing with mutable input enumerables. All in all, it should sort data everytime it is requested iterator.

Add cache operator

Currently, every time iterator is dereferenced whole computation process is required. Cache operator would store the data at some point to avoid computing same data multiple times.

Add possibility to compose operations

Currently the whole "flow" of data from source through operators to sinks is required for operator | to work properly. It would be useful to be able to compose more complex operators using the ones provided without need to specify input and/or output.

Implement fold_left operator

Operator fold_left

Input

Enumerable and folding functiion. Optionally folding start value
Enumerable, folding function and folding start value. If start value is not given, default value of the enumerable value type is used as initial.

Output

Folded value depending on folding function.

Additional info

As fold is not so easy to describe here is given quite good explanation:
https://en.wikipedia.org/wiki/Fold_(higher-order_function)

Example 1

const auto input = { 1, 2, 3, 4, 5, 6 };
//sum example
const auto output = input | fold_left((const auto &a, const auto &b)[]{ return a + b; });
//output should be 21

Example 2

const auto input = { 1, 2, 3, 4, 5, 6 };
//sum example
const auto output = input | fold_left((const auto &a, const auto &b)[]{ return a + b; }, 2/*fold initial value*/);
//output should be 23

Implement keys operator

Operator keys

Input

Associable enumerable.

Output

Enumerable to iterate through keys of given associable enumerable.

Example

const auto input = { std::make_pair(1, 2), std::make_pair(3, 4), std::make_pair(5, 6) };
const auto output = input | keys;
for(const auto &i : output)
    std::cout << i;
//output should be 1, 3, 5

Update README.md

Lot's of features has been added since last readme update. There is also a lot to clarify and fix.

Change folder structure of library

Root should be directory include. Inside should go tpl directory with its contents. Operation directory sholud be renamed to operator.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.