Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 for this function? maybe it can be described with some Ramda magic?


Edit to clarify:

What I'm looking for is similar to Ramda's partial,

partial(f, [a])

Except that partial is more like:

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

I.e the b in the case of partial is unwanted.

like image 305
Sam Pettersson Avatar asked Dec 18 '22 00:12

Sam Pettersson


2 Answers

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.

like image 167
Jared Smith Avatar answered Jan 05 '23 09:01

Jared Smith


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.

like image 21
corazza Avatar answered Jan 05 '23 08:01

corazza