map! evaluates twice

Antonio antonio at abrevia.net
Fri Jun 10 20:33:05 UTC 2022


When mapping and filtering, the last mapped element is evaluated 
twice... Is it the expected behaviour?

```d
void main()
{
     import std.algorithm, std.stdio;
	
     [1,2,3,4,5].
		map!((x){
         	writeln("mapping ", x);
         	return x;
     	}).
		filter!(x=>x>2).
		front.
		writeln();
}
```

Output
```
mapping 1
mapping 2
mapping 3
mapping 3
3

```


More information about the Digitalmars-d-learn mailing list