Logo

Programming-Idioms

History of Idiom 57 > diff from v30 to v31

Edit summary for version 31 by :
[D] Duplicate answer and in-code comments

Version 30

2016-02-16, 16:10:52

Version 31

2016-02-16, 16:24:03

Idiom #57 Filter list

Create list y containing items from list x satisfying predicate p. Respect original ordering. Don't modify x in-place.

Idiom #57 Filter list

Create list y containing items from list x satisfying predicate p. Respect original ordering. Don't modify x in-place.

Imports
import std.algorithm;
Imports
import std.algorithm;
Code
auto _y = _x.filter!(_p)

// actual example
auto y = [1, 2, 3, 4, 5].filter!(a => a%2==0); // y is a range containing only [2, 4]
Code
auto y = [1, 2, 3, 4, 5].filter!(a => a%2==0);
Comments bubble
Actual example.
y is a range containing only [2, 4]