Higher order functions
The pattern you’re referring to is known as a higher-order function. In this case, createFormValueSelector is a higher-order function because it returns another function. This is a common pattern in JavaScript, especially in functional programming and libraries like Redux. Here’s a brief explanation:
Higher-order function: A function that takes one or more functions as arguments, or returns a function as its result.
In your code, createFormValueSelector takes formName and field as arguments and returns a function that takes state as an argument. This returned function then uses these arguments to retrieve a specific value from the state.
const createFormValueSelector = (formName, field) => state => _.get(state.forms[formName], field);