Poorman's curry

Before you interject and say we should be using promises, We know.

I've always heard Currying described as "A function that returns a function until all of its arguments are satisfied." It's commonly used to make utility functions. The classic example is always some adder function that has you'd never see in actual code. Below is an example of a very simple Curry that we used to help keep all of our verbs on our service class consistent.

var verb = v => function(options) {  
  var {command, data, successCallback, failCallback, timeout} = options;
  this.request({
    verb: v,
    command: command,
    data: data,
    successCallback: successCallback,
    failCallback: failCallback,
    timeout: timeout
  });
};

class Service {  
  get: verb('GET');
  put: verb('PUT');
  post: verb('POST');
  delete: verb('DELETE');
  request(options) {
    //$.ajax or http or superagent calls made here
  }
}

The confusing part of the above code that made my head hurt at first is v => function(options) {. At first glance you think it's just another anonymous function. It's not though. Arrow functions have an implicit return so this actually returns a function defition.