I do this a lot : `(1..100).forEach{ }` but I neve...
# announcements
t
I do this a lot :
(1..100).forEach{ }
but I never reference
it
and my linter get's upset w/ me. Is there a better way to do this?
n
You just want to do something 100 times, but you don't need the value?
for starters, I think you could use repeat
although that has the same issue, in principle
n
repeat(100) { }
seems more natural to me. No idea if your linter (which one?) agrees
1
n
yeah, I agree it's a lot more natural for the use case. surprisingly though (to me), repeat still passes the integer to the lambda. so you'll still have an unused
it
. I suspect that hte linter isn't hardcoded to include/exclude certain functions but I could be wrong.
I'm not really sure I'm a huge fan of a linter complaining about unused function parameters, including
it
it is implicit, so there's lots of reasons why it would be unused. more generally, sometimes your signature is dictated by say inheritance, and you aren't using some parameters
I remember having a check like this in C++ and it had millions of false positives, for valid reasons like this, so we disabled it as well
t
Ooo.
repeat()
I like that better. learned something new. Thanks!
yeah. I'm not sure complaining about an unused implied is very useful either. might disable as well.
l
Which linter are you using?
I think Detekt doesn't complain about repeat, for example
t
Just the built in one in intelij
d
@jonross Does the IntelliJ linter still complain if you explicitly don't use the parameter with
_ ->
? I'm guessing that it will be satisfied, and if so this should be the preferred syntax.