[英]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.