Joshua Hansen
05/31/2024, 3:11 PMval example = funWithLambdaParam(arg1) {} // This just looks ugly to me
I was hoping I could just pass in something like ::Unit
but that doesn't seem to be a featureLarry Garfield
05/31/2024, 3:14 PMfunWithLambda(arg1, {})
should still work just as well, no?Joshua Hansen
05/31/2024, 3:17 PMLarry Garfield
05/31/2024, 3:18 PMRiccardo Lippolis
05/31/2024, 3:22 PMfunWithLambda
is your own function, you could simply add {}
as the default value of your parameter, like fun funWithLambda(arg1: Int, f: () -> Unit = {}) { ... }
otherwise you could define a constant somewhere like val noOp = {}
and pass that to funWithLambda
instead, but it would only work for lambda's without parameters of courseJoshua Hansen
05/31/2024, 3:22 PM::Unit
would be a nice way to represent "a function which takes no parameters and returns Unit" but it's just syntax sugar blob shrug If this wasn't kotlin with all of its bells and whistles, to be fair, I wouldn't be complainingWout Werkman
05/31/2024, 3:29 PMfun Unit(): Unit = Unit
Larry Garfield
05/31/2024, 3:30 PMKlitos Kyriacou
05/31/2024, 3:40 PM{}
IntelliJ warns me that it
is an unused parameter and suggests to change it to { _ -> }
🤮Joshua Hansen
05/31/2024, 3:45 PMval example = funWithLambda(arg1, fun() = Unit)
Joshua Hansen
05/31/2024, 3:46 PMfun