Skip to content

Instantly share code, notes, and snippets.

@owskio
Last active August 29, 2015 14:04
Show Gist options
  • Save owskio/8c3b2511fde46a41e69a to your computer and use it in GitHub Desktop.
Save owskio/8c3b2511fde46a41e69a to your computer and use it in GitHub Desktop.
Combinator Use Case: Adding AJAX Defaults
// ...
//AJAX DEFAULTS
basicAjax = addDefaults($.ajax,{
type: "GET",
dataType: 'json',
contentType: 'application/json',
error: function (jqXHR,textStatus,errorThrown) {
/* do some default error handling */
}
}),
//...
alter = function (o,k,f) {
o[k] = f(o[k]);
return o;
},
alterThe = curry3(counterClock(alter)),
//...
ajax = chain(
//Don't forget our blessed ASP.NET virtual
//path which changes all the friggin time
alterThe('url',function(u){
return util.virt(u);
}),
//Or simply:
//alterThe('url',util.virt),
basicAjax
),
//...
@owskio
Copy link
Author

owskio commented Aug 2, 2014

We can use simple combinators to add default arguments to functions which take single objects as argument collections, or later, we can use simple combinators to alter the functionality of our functions by prefixing argument-object mutators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment