DEV Community

Discussion on: Function Currying, What's the use?

Collapse
 
aledwassell profile image
Aled Wassell

Thanks for all the replies, so I finally found an application for currying, your advice was really useful!
This week I have been working on getting pagination working on a list of lists represented as tables that might have thousands and thousands of results.
So querying the server with page number and page size was key to getting it all working.
Users will select a list in a table to display the results within that list as another table and should be able to paginate.

get_list_curry = function (list_id) {
  return (search_params) => {
    return new Promise(
      function (resolve, reject) {
        numbersProvider.get({id: list_id}, {}, (data) => {
          list = data;
          resolve();
        });
      }
    );
  };
};
 //...
let paginate = get_list_curry(list_id);

paginate({pageNumber: 1, pageSize: 25});
paginate({pageNumber: 2, pageSize: 50});
paginate({pageNumber: 3, pageSize: 75});

Thanks for the replies.

Aled