Created
March 13, 2017 17:17
-
-
Save deyindra/4538dde6f0b1ff0f92632735bb186dc4 to your computer and use it in GitHub Desktop.
Lazy Prime Stream
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
object PrimeStream { | |
def apply(end : Int):Stream[Int] = { | |
def greater:(Int,Int) =>Boolean = (x,y) => x>=y | |
def transform: (Int) => Int = (x) => x+1 | |
val intStream:Stream[Int] = Stream(2,end)(greater,transform) | |
def primeStream(stream:Stream[Int]) : Stream[Int] = { | |
new ConStream[Int](stream.head, primeStream(Stream(stream.tail)(_%stream.head!=0))) | |
} | |
primeStream(intStream) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment