Logo

Programming-Idioms

History of Idiom 135 > diff from v16 to v17

Edit summary for version 17 by programming-idioms.org:
[D] typo

Version 16

2018-09-21, 13:15:55

Version 17

2018-09-22, 15:17:45

Idiom #135 Remove item from list, by its value

Remove at most 1 item from list items, having value x.
This will alter the original list or return a new list, depending on which is more idiomatic. If there are several occurrences of x in items, remove only one of them.

Idiom #135 Remove item from list, by its value

Remove at most 1 item from list items, having value x.
This will alter the original list or return a new list, depending on which is more idiomatic. If there are several occurrences of x in items, remove only one of them.

Imports
import std.algorithm;
Imports
import std.algorithm;
Code
items = items.remove(items.countUntil!(a => a == x));
Code
items = items.remove(items.countUntil!(a => a == x));
Comments bubble
D statndard library includes a comprehensive collection of algorithm preventing to write loops and minimizing the risk of bugs that they imply.
Comments bubble
D standard library includes a comprehensive collection of algorithms preventing to write loops and minimizing the risk of bugs that they imply.
Doc URL
https://dlang.org/phobos/std_algorithm_mutation.html#remove
Doc URL
https://dlang.org/phobos/std_algorithm_mutation.html#remove
Demo URL
https://run.dlang.io/is/1SjSfR
Demo URL
https://run.dlang.io/is/1SjSfR