Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Can you tweak your function to stop filling the first time a zero is encountered? That's a simple one-line change with the for loop, but a puzzle for the functional iteration.

In Rust:

  a.iter_mut().take_while(|i| *i == 0).for_each(|i| *i = 0)
And it's as fast as hand-written for loop.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: