Introducing folly::partial
authorSven Over <over@fb.com>
Tue, 16 Aug 2016 15:42:54 +0000 (08:42 -0700)
committerFacebook Github Bot 4 <facebook-github-bot-4-bot@fb.com>
Tue, 16 Aug 2016 15:53:26 +0000 (08:53 -0700)
commit6a287baae2b85280c1fc9faa42802f1f8596e569
tree315b3ef116991a87303c1ba47382ebb96abaf16a
parent6ba2117b74f6b4ebec8d1b9ab771d77e35a252e4
Introducing folly::partial

Summary:
This diff adds folly::partial, a function to partially apply
a set of zero or more arguments to a callable. It is similar
to Python's `functools.partial`.

`folly::partial` takes a callable object and additional
arguments and returns a callable with those additional
arguments bound to it. When the returned callable is invoked
with additional arguments, those are appended to the set of
arguments that were passed to `folly::partial`.

It is similar to `std::bind`, but more simple as it does not
support reordering of parameters, but also does not
require you to know how many arguments will be
eventually passed to the callable. Also, `std::bind`
does not support move-only types being passed by-value.
`folly::partial` does:

  void someFunc(std::unique_ptr<Foo>, int);
  auto p = folly::partial(&someFunc, std::move(foo_unique_ptr));
  ...
  std::move(p)(42);

Reviewed By: mhx

Differential Revision: D3252539

fbshipit-source-id: ee093771ac732fa70052b9908dcb75e90ba80efe
folly/Makefile.am
folly/Partial.h [new file with mode: 0644]
folly/test/Makefile.am
folly/test/PartialTest.cpp [new file with mode: 0644]