On Monday, 18 April 2016 at 12:02:24 UTC, thedeemon wrote:
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)

If it's good enough for Haskell, maybe it's good enough for us. "iterate" does sound like a decent name.

Reply via email to