Skip to content

Instantly share code, notes, and snippets.

@dkokic
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkokic/e32a219b3eed9307f4df to your computer and use it in GitHub Desktop.
Save dkokic/e32a219b3eed9307f4df to your computer and use it in GitHub Desktop.
purely functional implementation of prime numbers generator
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