Created
January 13, 2015 16:44
-
-
Save unscriptable/5d5595769565e936c49d to your computer and use it in GitHub Desktop.
Multiplexed streams compete
This file contains 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
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