Last active
August 29, 2015 13:59
-
-
Save mperry/10878344 to your computer and use it in GitHub Desktop.
This file contains 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
@Grab("org.functionaljava:functionaljava:3.1") | |
import fj.F | |
import fj.data.Stream | |
import groovy.transform.Memoized | |
@Memoized | |
Stream<Integer> primes() { | |
Stream.cons(2, { -> | |
Stream.range(3).filter { Integer i -> | |
primes().takeWhile({ Integer j -> j * j <= i } as F).forall { Integer k -> i % k != 0 } | |
} | |
}) | |
} | |
println primes().takeWhile { it <= 20 } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment