-
Notifications
You must be signed in to change notification settings - Fork 5
race
Ivan Kleshnin edited this page Jan 26, 2016
·
1 revision
import Most from "most";
// amb :: Stream a -> Stream a -> Stream a
// return a stream that imitates the input stream with
// the earliest first event
let amb = (s1, s2) => Most.merge(mapToSelf(s1), mapToSelf(s2)).take(1).join();
// helper
let mapToSelf = s => s.take(1).map(x => s.startWith(x));
// example
let a = Most.periodic(100, "a").delay(1);
let b = Most.periodic(100, "b");
// emits infinitely many bs and no as
amb(a, b).observe(console.log);