Last active
August 29, 2015 14:12
-
-
Save dkokic/e32a219b3eed9307f4df to your computer and use it in GitHub Desktop.
purely functional implementation of prime numbers generator
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 from(n: Integer): Stream[Integer] = n #:: from(n+1) | |
def sieve(input: Stream[Integer]): Stream[Integer] = input.head #:: sieve(input.tail.filter(_ % input.head != 0)) | |
def primes = sieve(from(2)) | |
primes take 10 print |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment