Created
December 26, 2015 20:24
-
-
Save HomenSimpsor/3eea1d68d86d5992eed0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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