Lambda Tuple with Map Reduce

2022-04-20 Thread Salih Dincer via Digitalmars-d-learn
```d alias type = real; alias func = type function(type a); void main() { import std.range; auto range = 10.iota!type(14, .5); alias fun1 = (type a) => a * a; alias fun2 = (type a) => a * 2; alias fun3 = (type a) => a + 1; alias fun4 = (type a) => a - 1; alias fun5 = (type a) => a

Re: Lambda Tuple with Map Reduce

2022-04-20 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 20 April 2022 at 08:04:42 UTC, Salih Dincer wrote: I get an unexpected result inside the second foreach() loop. Anyone know your reason? It's my fault, here is the solution: ```d foreach(fun; funs) { range.map!(a => fun(a)) .reduce!sum .write

Re: Lambda Tuple with Map Reduce

2022-04-20 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 20 April 2022 at 08:37:09 UTC, Salih Dincer wrote: On Wednesday, 20 April 2022 at 08:04:42 UTC, Salih Dincer wrote: I get an unexpected result inside the second foreach() loop. Anyone know your reason? It's my fault, here is the solution: ```d foreach(fun; funs) { ra

Re: Lambda Tuple with Map Reduce

2022-04-20 Thread JG via Digitalmars-d-learn
On Wednesday, 20 April 2022 at 08:04:42 UTC, Salih Dincer wrote: ```d alias type = real; alias func = type function(type a); [...] I think technically you should have save after range in that loop.