Re: Function called twice

2019-08-02 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 2 August 2019 at 21:44:28 UTC, Jordan Wilson wrote: Hello, I don't quite understand why isEven is called twice in the 2nd example? auto isEven(int n) { n.writeln; return (n % 2) == 0; } void main() { auto z = [1,2,3]; // outputs 1 2 3

Re: Function called twice

2019-08-02 Thread Boris Carvajal via Digitalmars-d-learn
On Friday, 2 August 2019 at 21:44:28 UTC, Jordan Wilson wrote: Hello, I don't quite understand why isEven is called twice in the 2nd example? auto isEven(int n) { n.writeln; return (n % 2) == 0; } void main() { auto z = [1,2,3]; // outputs 1 2 3

Re: Function called twice

2019-08-02 Thread Jordan Wilson via Digitalmars-d-learn
On Friday, 2 August 2019 at 22:35:53 UTC, Adam D. Ruppe wrote: On Friday, 2 August 2019 at 21:44:28 UTC, Jordan Wilson wrote: // outputs 1 2 2 3 z.map!(a => tuple!("number","iseven")(a, a.isEven)) .filter!(a => a.iseven) .array; I *think* what's happening here

Re: Function called twice

2019-08-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 2 August 2019 at 21:44:28 UTC, Jordan Wilson wrote: // outputs 1 2 2 3 z.map!(a => tuple!("number","iseven")(a, a.isEven)) .filter!(a => a.iseven) .array; I *think* what's happening here is first it calls map() first going into the filter... then it

Function called twice

2019-08-02 Thread Jordan Wilson via Digitalmars-d-learn
Hello, I don't quite understand why isEven is called twice in the 2nd example? auto isEven(int n) { n.writeln; return (n % 2) == 0; } void main() { auto z = [1,2,3]; // outputs 1 2 3 z.map!(a => tuple!("number")(a)) .filter!(a => a.nu