I want to implement a higher order function (hof) that essentially works like F# style forward-pipe operator (passes a value as the first argument to another function, myFunc). The only way I can think of is this:
function hof(val, myFunc, args_array) {...}
where args_array is the array of arguments for the call to myFunc (excluding the first argument, since that's going to be val)
But this doesn't look very elegant to me. Is there a better way to do this?
Edit: I found this on github https://gist.github.com/aaronpowell/d5ffaf78666f2b8fb033. But I don't really understand what the sweet.js code is doing. It'd be very helpful if you could annotate the code, specifically:
case infix { $val | _ $fn($args (,) ...) } => {
return #{
($fn.length <= [$args (,) ...].length + 1 ? $fn($args (,) ..., $val) : $fn.bind(null, $args (,) ..., $val))
}
}
case infix { $val | _ $fn } => {
return #{
($fn.length <= 1 ? $fn($val) : $fn.bind(null, $val))
}
}