[Ramda] Simple log function for debugging Compose function / Using R.tap for logging

const log = function(x){
  console.log(x);
  return x;
}

const get = R.curry(function(prop, obj){
  return obj[prop];
})

var people = [
  {name: "Wan"},
  {name: "Zhentian"}
];

var res = R.compose(
  get('name'),
  log,
  R.head
)(people);

console.log(res);

 

Using R.tap:

const log = curry((desc, x) => R.tap(() => console.log(desc, JSON.stringify(x, null, 2)), x));

 

posted @ 2016-09-04 02:58  Zhentiw  阅读(183)  评论(0编辑  收藏  举报