Skip to content

Instantly share code, notes, and snippets.

@unscriptable
Created January 13, 2015 16:44
Show Gist options
  • Save unscriptable/5d5595769565e936c49d to your computer and use it in GitHub Desktop.
Save unscriptable/5d5595769565e936c49d to your computer and use it in GitHub Desktop.
Multiplexed streams compete
module.exports = compete;
/**
* Filter function to determine which of all multiplexed streams
* is currently winning.
* TODO: change this so that multiple streams can be winners, but
* don't use an array of winners. Perhaps inject another function?
*/
function compete (identify, compare) {
var winner, wid;
return function (value) {
var id = identify(value);
if (id === wid || compare(value, winner) >= 0) {
winner = value;
wid = id;
}
return winner == value;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment