This message was deleted.
# language-proposals
s
This message was deleted.
5
1
d
I do this pretty often myself. I'm not sure if it's quite worthy of an operator, but it does remind me of the pipeline operator some languages have (like Elixer I think?)
k
does this mean you'd be able to do
makeThing()?&.setup()
?
k
isn’t this that you are looking for? https://pl.kotl.in/Jlu_woa27 instead of an operator you could create an infix
Dart has a
cascade notation
with the
..
operator. I am not sure if this is useful but it basically reduces the apply to an operator. The only problem with replacing functions with operators is after a while everyone wants their own operator. there are languages which supports creating your own but for a newcomer it is hard to understand without codebase specific knowledge. I agree with you, sometimes it would be comfortable to have a cascade operator or add your own but I read somewhere that the Kotlin team decided to avoid such for better readability.
k
I do this often as well, especially in functions without a body to avoid introducing a
tmp
variable, but I don't think any of the proposed syntax in this thread is actually an improvement.
3
k
@karelpeeters do you have a preference for syntax?
k
I can't think of any better idea myself either, honestly I think
apply
is fine as-is.
👍 4
1
h
i think similar to how you can do the same thing in java, double curly brackets could work
Copy code
Foo() {{ 
    //things 
}}
🤔 1
in current version, you can also just do this:
Copy code
class Foo(var bar: Int = 0) {
    constructor(op: Foo.() -> Unit) : this() {
        op()
    }
}

val foo = Foo {
    bar++
    println(this)
    // etc
}
k
And that's the problem, it's ambiguous with a lambda parameter that returns another lambda.
a
Would this function like DartLang's
..
call? I don't mind Dart's syntax for it, but personally I prefer excluding it from the language in favor of
apply