"fold": a replacement for "reduce"
Simen Kjærås
simen.kjaras at gmail.com
Wed Mar 26 07:55:53 PDT 2014
On 2014-03-25 21:16, "Nordlöw" wrote:
>> You have no guarantees that you'll have "stability" of the returned type.
>
> What do you mean with "stability" of the return type?
>
>> More often than not, it *is* stable, but there are cases where it is not.
>
> Could you gives examples of when it's stable and when it's not?
I'm not entirely certain if this is what monarch_dodra meant, but it's
my understanding of the terms:
Stable:
double[] arr = [1, 2, 3, 4];
auto a = arr[0] * arr[1];
auto b = a * arr[2];
a is of type double, b is of type double.
Unstable:
Consider a range of imaginary numbers, reduced with *.
idouble[] arr = [1i, 2i, 3i, 4i];
auto a = arr[0] * arr[1];
auto b = a * arr[2];
a is of type double, b is of type idouble. When you consume the next
element, the result would be double again, and it oscillates like that.
--
Simen
More information about the Digitalmars-d
mailing list