lodashのtapで処理を挟む

lodashのtapを使うと、チェーンの間に処理を挟むことができます。

https://lodash.com/docs/#tap

例えば、途中の値をconsole.logで確認したい時には、以下のようにします。

const array = [1,2,3];

const twoTime = v => v * 2
const debug = v => {console.log(v)}

const result = _(array)
.map(twoTime)
.tap(debug)
.reverse()
.value();

console.log(result); 

//[2, 4, 6]
//[6, 4, 2]

必要が無くなったら、ここだけ削除すれば良いので、バグの可能性も減りそうです。