https://kotlinlang.org logo
Title
h

Hullaballoonatic

04/17/2019, 7:58 PM
also can you conceive of a possibility where brackets could and should be omitted? i'm thinking things like 1 line lambda functions, e.g.
list.any it.hasFoo
c

Cody Engel

04/17/2019, 7:59 PM
Doesn’t
infix
already allow for that?
h

Hullaballoonatic

04/17/2019, 8:01 PM
i suppose it does? i've only used infix with traditional functions, not higher order ones.
👍🏻 1
b

bdawg.io

04/17/2019, 9:47 PM
There’s not really any need for infix with a higher order function parameter. they result in pretty much the same thing
infix fun A.apply(configure: A.() -> Unit): A {
    configure()
    return this
}
A() apply { doSomething() }
vs
fun A.apply(configure: A.() -> Unit): A {
    configure()
    return this
}
A().apply { doSomething() }
Concerning omitting of brackets, I would take the same position as no-bracket
if
statements in that they should be avoided and have brackets unless it’s used as an expression ie,
val a = if (b) "was true" else "was false"
it.hasFoo
is a bit ambiguous though and would probably be better expressed as
list.any(T::hasFoo)
instead of adopting a no-bracket lambda expression
2