Skip to content

Instantly share code, notes, and snippets.

@jweir
Last active August 29, 2015 14:28
Show Gist options
  • Save jweir/9d51b0ad94fa270c95d2 to your computer and use it in GitHub Desktop.
Save jweir/9d51b0ad94fa270c95d2 to your computer and use it in GitHub Desktop.
Naive pipes in javascript
function pipe(src){
var value = src;
return function(){
for(var i = 0; i < arguments.length; i++){
var fn = arguments[i];
value = fn.call(null, value);
}
return value
}
}
function addOne(v){ return v + 1 }
function timesTwo(v){ return v * 2 }
function minusOne(v){ return v - 1 }
pipe(1)(addOne,timesTwo,minusOne) // 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment