folly::gen, or Comprehensions->Folly
authorTom Jackson <tjackson@fb.com>
Fri, 22 Jun 2012 06:27:23 +0000 (23:27 -0700)
committerJordan DeLong <jdelong@fb.com>
Mon, 29 Oct 2012 23:32:26 +0000 (16:32 -0700)
commit506b9a329da4d173c6fb608a224f73287147511a
tree77083086cd22133807e214a968058a80118aaf13
parent99d9bfdd41e4999b2b5485a01b17a1a759fff559
folly::gen, or Comprehensions->Folly

Summary:
Moving Comprehensions library into Folly and refactoring its interface to be much more modular and composable. There are now two core abstractions:

# Generators: Standalone classes supporting ##apply()## and optionally ##foreach()##. These all inherit from ##GenImpl<T, Self>##.
# Operators: Standalone classes which, when composed with a generator, produce a new generator. These all inherit from ##OperatorImpl<Self>##.

These generators may be composed with ##operator|## overloads which only match ##const GenImpl<T, Self>&## on the left like ##gen | op##.  Additionally, generator may be consumed inline with ##gen | lambda## like ##gen | [](int x) { cout << x << endl; };##.

With this design, new operators may be added very simply without modifying the core library and templates are instantiated only exactly as needed.

Example:

```lang=cpp
auto sum = seq(1, 10) | filter(isPrime) | sum;
seq(1, 10) | [](int i) {
cout << i << endl;
};
```

Test Plan: Unit tests

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D542215
folly/experimental/Gen-inl.h [new file with mode: 0644]
folly/experimental/Gen.h [new file with mode: 0644]
folly/experimental/test/GenBenchmark.cpp [new file with mode: 0644]
folly/experimental/test/GenTest.cpp [new file with mode: 0644]