Skip to content

Instantly share code, notes, and snippets.

@beiske
Created October 2, 2013 13:08
Show Gist options
  • Save beiske/6793451 to your computer and use it in GitHub Desktop.
Save beiske/6793451 to your computer and use it in GitHub Desktop.
Attempt at making a streamwrapper that buffers the next result
def prefetch[A](slowSource: Stream[A]): Stream[A] = {
def fetch(stream: => Stream[A]) = {
Future {
stream(1)
}
}
def cons(head: Future[A], tail: => Stream[A]): Stream[A] = {
val next = fetch(tail)
Await.result(head, Duration.Inf) #:: cons(next, tail.tail)
}
slowSource.head #:: cons(fetch(slowSource.tail), slowSource.tail.tail)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment