Is there a ramda function that helps you add logging to piping/composition?

Viewed 665

I would like to add logging to a composed chain of functions like so

const f = R.compose(
  transformation2,
  doAlso(x => console.log(`id: ${x.id}`)),
  transformation1
)

Which would first apply transformation1 and then log the id of the resulting value before passing it to transformation2.

It would be quite easy to implement

doAlso = f => x => {
  f(x)
  return x
}

But it seems like it should be a quite common pattern. Is this concept called something? Does a similar function exist in FP libs like ramda?

1 Answers
Related