Skip to content Skip to sidebar Skip to footer

Is There A Name For This Function

I am looking for a name for the following function: (f, a) => () => f(a) Basically a function that returns a function which when called calls f with a. Is there a common name

Solution 1:

That's a thunk.

Essentially, it's a reified computation that you can pass around and evaluate on demand. There are all sorts of reasons one might want to delay evaluation of an expression (it may be expensive, it may have time-sensitive side effects, etc.).

Doing const enThunk = f => a => () => f(a); lets you pass around f(a) without actually evaluating it until a later point in time.

Solution 2:

I'd call that a special case of binding

If you have a function of two parameters, say f(x, y), then you can define g(y) = f(5, y). In that case, you bound the parameter x in f to the fixed point 5.

Solution 3:

I would call it prepared function with deferred calling.

The first part takes the function and argument and returns a function without calling the given function with argument. This is called later with explicit calling of the function.

Solution 4:

In JavaScript, this is likely referred to as bind. There might be a more specific name for this type of combinator in general (which is very similar to the apply combinator -> f => a => f(a)).

Simple to implement:

constbind = (f, a) => () =>f(a)

Solution 5:

it's a higher-order function.

A higher-order function is a function that takes at least one or more functions as an input or returns another function.

This definition satisfies the code:

(f, a) => () =>f(a)

as it's essentially a function returning another function.

Post a Comment for "Is There A Name For This Function"