Skip to content

Instantly share code, notes, and snippets.

@beizhedenglong
Last active July 18, 2019 06:45
Show Gist options
  • Save beizhedenglong/8b22f42415f6c35fa7b77a3f62b55055 to your computer and use it in GitHub Desktop.
Save beizhedenglong/8b22f42415f6c35fa7b77a3f62b55055 to your computer and use it in GitHub Desktop.
const streamMaker = (f) => {
const aux = x => [f(x), () => aux(x + 1)]
return () => aux(0)
}
const ones2 = streamMaker(x => x + 100)
const numberUntil = (s, predict) => {
const aux = (s, ans) => {
const [result, th] = s()
if (predict(result)) {
return ans
}
return aux(th, ans + 1)
}
return aux(s, 1)
}
console.log(numberUntil(ones2, x => x === 200))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment