my @primes = (1..∞).grep: *.is-prime; my @twin_primes = map { ($_, $_+2) }, @primes.grep: (*+2).is-prime;
infinite symbol gives away 6
So, yeah. Correct me if I'm wrong.
A slightly less listy pattern style is to declare types. Like I'd prefer this sort of declarative style:
subset Prime of Int where *.is-prime; subset TwinPrime of Prime where (* + (2|-2)).is-prime; my @twin_primes = grep TwinPrime, ^Inf;
How is performance on a task like this compared to, say, Python?