21 ms·
Yeah, trivial cases are trivial everywhere. I like your strength/weakness observation. But if you are mutating index variables, you have a hard case, and it pr
by millstone 6y ago
Yeah, trivial cases are trivial everywhere.
I like your strength/weakness observation. But if you are mutating index variables, you have a hard case, and it probably will be easier to express with a manual loop than trying to shoehorn it into awkward functional constructs.
An example is the "discard elements by a predicate" function, aka Vec::retain in Rust, std::remove in C++. Rust implements this using a for loop. Maybe it can be done with functional constructs, but it would be harder to write and to understand.
https://doc.rust-lang.org/src/alloc/vec.rs.html#1105 https://doc.rust-lang.org/src/alloc/vec.rs.html#1105
- deleted 6y ago[deleted]
- thedufer 6y agoBut Vec::retain is pretty close to one of the fundamental functional constructs for containers (it's the in-place version of filter). The argument here is that others should use functions like retain instead of re-implementing that nasty indexing logic. But I don't think it should be surprising that array-like containers are going to have to involve some indexing logic at some level.