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

  > def parsedLines = lines.withIndex().filter{l, i -> i < 1 || lines[i - 1] != 'a'}.collect{parseLine(it)}
In that Apache Groovy sample, you put an `l` as the first parameter to the `filter` but don't use it anywhere, which is not simple for people reading it. The logic instead requires you to refer to the global input `lines`, which is better expressed imperatively.

And btw in Groovy that code would probably only work on ASCII data.



Really is it so difficult to ignore one parameter for people reading that one liner? I could have used the underscore but honestly when I'm writing from the phone I don't usually care for small things that don't change absolutely nothing. At least my code doesn't have the bug that skips TWO lines after the a, like the original code, and it actually saves the parsed lines in a new collection rather than throwing them away and doing nothing at all apart from burning cpu. But for some strange reason you still prefer that obscure bug-ridden and useless imperative code rather than the self explaining and declarative functional version. Enjoy your imperative bugs :)


Any code that's not tested has bugs. As for reading code, when I read yours I can't work out why you put

  .filter{l, i -> i < 1 || lines[i - 1] != 'a'}
instead of

  .filter{l, i -> i < 1 || lines[i - 1][0] != 'a'}
to skip the line after one that begins with an 'a', or

  .filter{l, i -> i < 1 || lines[i - 1] != "a"}
to skip the line after one that is an "a". I'd need to go run it to work out what it does.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: