hof icon indicating copy to clipboard operation
hof copied to clipboard

apply - what is the utility of apply?

Open viboes opened this issue 8 years ago • 7 comments

Oh, I believe I have found why I don't understand. The template parameters TS are not part of the function apply This

template<class F, class... Ts>
constexpr auto apply(F&& f, Ts&&... xs);

should be

template<class F>
constexpr auto apply(F&& f);

The semantics given us

assert(apply(f)(xs...) == f(xs...));

But the usage is incompatible

assert(fit::apply(sum_f(), 1, 2) == 3);

that I believe should be

assert(fit::apply(sum_f())(1, 2) == 3);

Unfortunately the implementation is not inline at all.

viboes avatar Oct 04 '15 02:10 viboes

Oops, thats a mistake in the documentation. The semantics should be:

assert(apply(f, xs...) == f(xs...));

pfultz2 avatar Oct 05 '15 06:10 pfultz2

So the question remains, what is the utility of this function?

viboes avatar Oct 05 '15 06:10 viboes

That you want to call the first parameter with the rest of the parameters. One example, is to curry the functions parameters:

assert(compress(apply, f)(x, y, z) == f(x)(y)(z));

pfultz2 avatar Oct 05 '15 07:10 pfultz2

Ok, I see apply is the monoid operator on function composition.

Could you add this example or another more user friendly?

viboes avatar Oct 05 '15 22:10 viboes

Could you add this example or another more user friendly?

Yea I will.

pfultz2 avatar Oct 05 '15 22:10 pfultz2

The semantics must be fixed yet.

viboes avatar Mar 01 '16 00:03 viboes

Oh, should I add that to the "semantics" of apply? That might be a good idea.

pfultz2 avatar Mar 01 '16 00:03 pfultz2