[英]chaining curry functions with lodash
受关于咖喱函数的这篇文章的启发,我试图将它们链接起来,并提出了这个解决方案。 我不确定mixin,因为我不知何故lodash可能已经具备了这样的功能。 如果是这样,此函数称为什么?
var _ = require('lodash');
var get = _.curry(function(property, object) {return object[property]});
var map = _.curry(function(fn, objects){ return objects.map(fn) });
var json = {
"user": "hughfdjackson",
"posts": [
{ "title": "why curry?", "contents": "..." },
{ "title": "prototypes: the short(est possible) story", "contents": "..." }
]
}
_.mixin({
then:function(input, fn) {return fn(input);}
});
_(json)
.then(get('posts'))
.then(map(get('title')))
.tap(console.log)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.