import { compose } from "ramda"; let input = document.getElementById("input"); let inputBroadcaster = (listener) => { input.addEventListener("input", listener); return () => { input.removeEventListener("input", listener); }; }; let log = (value) => { console.log(value); }; let getTargetValue = (broadcaster) => (listener) => { let stop = broadcaster((event) => { listener(event.target.value); }); return stop; }; let stopOnCond = (cond) => (broadcaster) => (listener) => { let stop = broadcaster((value) => { if (cond(value)) { stop(); } else { listener(value); } }); return stop; }; const stopOnStop = stopOnCond((value) => value === "stop"); const stopOnInputStop = compose(stopOnStop, getTargetValue); stopOnInputStop(inputBroadcaster)(log);