use-function-first
v0.0.2
Published
Functional Programming tool to compose data-first/callback-last styled functions.
Downloads
3
Maintainers
Readme
Use Function First!
This is Functional Programming tool to compose data-first/callback-last styled functions.
Inspired by:
https://thenewcircle.com/s/post/1468/hey_underscore_you_are_doing_it_wrong_brian_lonsdorf
https://www.youtube.com/watch?v=m3svKOdZijA
Underscore style (Data First / Callback Last)
var _ = require('underscore');
var mapFirstTwo = function(data){
return _.map(data, function(item){
return _.first(item, 2);
});
};
Function First / Data Last style
1. Use Function
var use = require('use-function-first');
var underscore = require('underscore');
var mapFirstTwo = use(function(map, first){
return map( first (2));
}, underscore);
2. Compose Function
var composeFn = require('use-function-first');
var _ = require('underscore');
var mapFirstTwo = composeFn(['map first', 2], _ );
Result
mapFirstTwo(["one","two","three"]); // ["on","tw","th"]
3. File-system API
var filterFiles = composeFn(
'readdir filter filesOnly',
require('fs'),
Array,
{filesOnly: function( fileName, callback ){
}}
);
filterFiles("./");