www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - iota where step is a function

reply Ben Jones <fake fake.fake> writes:
Is there a range like iota in phobos where step is a function?  I 
want to specify begin/end and have the "step" be next = 
fun(prev).  Should be easy to write, but don't want to reinvent 
the wheel.
May 24 2023
next sibling parent Rene Zwanenburg <renezwanenburg gmail.com> writes:
On Wednesday, 24 May 2023 at 16:39:36 UTC, Ben Jones wrote:
 Is there a range like iota in phobos where step is a function?  
 I want to specify begin/end and have the "step" be next = 
 fun(prev).  Should be easy to write, but don't want to reinvent 
 the wheel.
I think you’re looking for either recurrence() or sequence(), also defined in std.range.
May 24 2023
prev sibling parent reply anonymouse <anony mouse.com> writes:
On Wednesday, 24 May 2023 at 16:39:36 UTC, Ben Jones wrote:
 Is there a range like iota in phobos where step is a function?  
 I want to specify begin/end and have the "step" be next = 
 fun(prev).  Should be easy to write, but don't want to reinvent 
 the wheel.
````D import std.stdio; import std.range: iota; void main() { iota(10, 0, -1).writeln; } ````
May 24 2023
parent reply anonymouse <anony mouse.com> writes:
On Thursday, 25 May 2023 at 00:18:44 UTC, anonymouse wrote:
 On Wednesday, 24 May 2023 at 16:39:36 UTC, Ben Jones wrote:
 Is there a range like iota in phobos where step is a function? 
  I want to specify begin/end and have the "step" be next = 
 fun(prev).  Should be easy to write, but don't want to 
 reinvent the wheel.
````D import std.stdio; import std.range: iota; void main() { iota(10, 0, -1).writeln; } ````
I think I misunderstood what was being asked here.
May 24 2023
parent Ben Jones <fake fake.fake> writes:
On Thursday, 25 May 2023 at 00:39:02 UTC, anonymouse wrote:
 I think I misunderstood what was being asked here.
My particular use case is to step using * rather than +, so something like for(i = 1; i < N; i *= 2). `sequence` worked for what I was doing well enough
May 24 2023