A Recurring Question

thedeemon via Digitalmars-d digitalmars-d at puremagic.com
Mon Apr 18 05:02:24 PDT 2016


On Sunday, 17 April 2016 at 15:23:50 UTC, w0rp wrote:
> auto unaryRecurrence(alias func, T)(T initialValue) {
>     return recurrence!((values, index) =>  
> func(values[0]))(initialValue);
> }

> This is kind of neat. My question is, should something like 
> this function be included in std.range? Either way, it turned 
> into an example of something cool you can do with D.

It really looks like "iterate" combinator from Haskell's standard 
library:

iterate :: (a -> a) -> a -> [a] Source

iterate f x returns an infinite list of repeated applications of 
f to x:
iterate f x == [x, f x, f (f x), ...]

http://hackage.haskell.org/package/base-4.8.2.0/docs/Prelude.html#v:iterate

(which could be a hint to stdlib-includability and naming)



More information about the Digitalmars-d mailing list