I've read in a book that the function signature of tap function (also called K-Combinator) is below:
tap :: (a -> *) -> a -> a
"This function takes an input object a and a function that performs some action on a. It runs the given function with the supplied object and then returns the object."
- Can someone help me to explain what is the meaning of star (*) in the function signature?
- Are below implementation correct?
- If all the three implementation are correct, which one should be used when? Any examples?
Implementation 1:
const tap = fn => a => { fn(a); return a; };
tap((it) => console.log(it))(10); //10
Implementation 2:
const tap = a => fn => { fn(a); return a; };
tap(10)((it) => console.log(it)); //10
Implementation 3:
const tap = (a, fn) => {fn(a); return a; };
tap(10, (it) => console.log(it)); //10