Hacker News new | past | comments | ask | show | jobs | submit login

I think Infinity can be handled lot more elegantly in Python.

Here is my response with the same problem solved in Python.


You can replace your `integers` function with `itertools.count` (same signature but defaults to starting at 0), and `take` with `itertools.islice`.

Didn't realize I could use `itertools.count`. In fact, it accepts a `start` parameter.

The `take` function is borrowed from Haskell. It feels lot more natural to say/read `take(10, primes())`, than `islice(primes(), 10)`.

perl6 -e 'my $integers := gather for 0..Inf { take $_ }; say $integers[2]'

There's no memoization in that approach however.

Registration is open for Startup School 2019. Classes start July 22nd.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact