4 ms·
Here's an abomination of my own design in Rust for example: for (index, node) in nodes .expect("Error: No blocks for the Body") .children()
by aquariusDue 2y ago
Here's an abomination of my own design in Rust for example:
for (index, node) in nodes
.expect("Error: No blocks for the Body")
.children()
.expect("Error: blocks node has no children")
.nodes()
.iter()
.enumerate()
{
let block = Block::new(node, index);
self.blocks.push(block);
}
- maleldil 2y agoWhy the for loop instead of mapping the enumerate iterator into Block::new and collect::Vec?
- aquariusDue 2y agoI lack a good answer other than it didn't occur to me, now I have some code to refactor. Thanks!
- maleldil 2y agoFWIW, I've had to write similar code when there's some complex "folding" operation. I use map/filter a lot, but fold/reduce/accumulate always seemed harder to understand than a for loop. I also prefer nested loops rather than nested iterators.