Skip to content

Instantly share code, notes, and snippets.

@HomenSimpsor
Created December 26, 2015 20:24
Show Gist options
  • Save HomenSimpsor/3eea1d68d86d5992eed0 to your computer and use it in GitHub Desktop.
Save HomenSimpsor/3eea1d68d86d5992eed0 to your computer and use it in GitHub Desktop.
var bind = function(f) {
return function(tuple) {
var x = tuple[0],
s = tuple[1],
fx = f(x),
y = fx[0],
t = fx[1];
return [y, s + t];
};
};
const bind =
fn => {
return tuple => {
// Incoming number and message.
// E.g. [ 0.5, '(start) ' ]
let [ inNum, inMsg ] = tuple;
// Number and message result coming running `fn(inNum)`.
// E.g. sineWithMsg(0.5)
// => [ 0.47942, 'sine was called. ' ]
let [ resNum, resMsg ] = fn(inNum);
// Output the result number and a concatenated message.
// E.g. [ 0.47942, '(start) sine was called. ' ]
return [ resNum, (inMsg + resMsg) ];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment