No they are quite different.
However, both thunks
and currying
have applications in functional programming
.
Thunks
Thunks are a functional programming
technique used to delay computation.
This helps us greatly in context of redux
.
So, what do we do when we want to delay computation when we dispatch
an action?
We use thunks
as a middleware.
It is very simple
export default function thunkMiddleware({ dispatch, getState }) {
return next => action =>
typeof action === 'function' ?
action(dispatch, getState) :
next(action);
}
This is largely the implementation of thunks
in redux-thunk
.
It basically just checks whether the dispatched
action is a function, if not it just passes it as is.
You can read the core implementation here. It is just 14 lines.
Currying
Currying is converting a single function of n arguments into n functions with a single argument each.
So for example if we have a function that takes three parameters a,b & c
let result = fn(a,b,c)
When we apply currying to it, then it becomes
let applyCurrying = curriedFn(fn);
let result = applyCurrying(a)(b)(c);
A trivial implementation of curriedFn:
const curriedFn = a => b => c => ( do compuation with a,b,c );
In currying, each function takes exactly one parameter.