Created
October 2, 2013 13:08
-
-
Save beiske/6793451 to your computer and use it in GitHub Desktop.
Attempt at making a streamwrapper that buffers the next result
This file contains hidden or 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
| 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