matches.jsJavaScript模式匹配库
matches.js 是一个开源的JavaScript模式匹配库,示例代码:
var pattern = require("matches").pattern;
var mymap = pattern({
'_, []' : function () {
return [];
},
'f, [x, xs...]' : function (f, x, xs) {
return [f(x)].concat(mymap(f, xs));
}
});
// [2, 4, 6, 8]
mymap(function (x) { return x * 2; }, [1, 2, 3, 4]);评论
