Do you know a much nicer way to take just the n-th item of a lazy range?
import std.stdio, std.array, std.range;
void main() {
auto fib = recurrence!("a[n-1] + a[n-2]")(1, 1);
writeln(array(take(fib, 10)).back);
}
In Python I use next(isslice(x, n, n+1)):

Do you know a much nicer way to take just the n-th item of a lazy range?
import std.stdio, std.array, std.range;
void main() {
auto fib = recurrence!("a[n-1] + a[n-2]")(1, 1);
writeln(array(take(fib, 10)).back);
}
In Python I use next(isslice(x, n, n+1)):

Assuming that it's a forward range rather than an input range:
auto s = range.save;
s.popFrontN(n - 1);
writeln(s.front);
The problem is that you have to process a lazy range before you can get at any
of its elements, and once you've processed an element, it's no longer in the
range. So, you pretty much have to save the range and operate on a copy of it.
At that point, you can remove the elements prior to the one you care about and
then take the one you care about from the front of the range.
- Jonathan M Davis

Okay, so you need to do popFrontN(s, n - 1). I'm too used to arrays which allow
you to use that sort of syntax. That and not bothering with [] when slicing
seem
to be the two biggest problems that I'm seeing when dealing with ranges which
aren't arrays. I'm just too used to arrays.
- Jonathan M Davis