const tap = (value) =>
(fn) => (
typeof(fn) === 'function' && fn(value),
value
)
tap('espresso')((it) => {
console.log(`Our drink is '${it}'`)
});
Ok I understand that tap
accept an argument called value
that later is espresso
and returns another function with an argument (fn)
. Then that function checks if his argument is a function and if so then it calls that function, Then it returns value
(even if fn is not a function) (And yes I understand that tap is a combinator, I just no get how it is working)
So when calling tap values
becomes espresso
and fn
is this function right?
((it) => {
console.log(`Our drink is '${it}'`)
});
So I understand that fn
is that anonymous function that accepts (it) as argument. Then I returns console.log()
and I understand that ${it}
used to show the string on ‘value’. But I don’t get how did it
become value
. So how does it
get espresso
??? And everything I just said is correct?
Thank you