https://kotlinlang.org logo
#language-proposals
Title
# language-proposals
e

Eric Ou

06/29/2022, 9:06 AM
There should be a
Copy code
inline fun <T> T?.println(): T? {
    println(this)
    return this
}
so I dont have to move my caret around when trying to debug
👍 1
d

dmitriy.novozhilov

06/29/2022, 9:11 AM
How you will print empty line, if such function would exist?
e

Eric Ou

06/29/2022, 9:12 AM
println()
Im not saying to get rid of the original println, just add a extension method to easily print an object inline
d

dmitriy.novozhilov

06/29/2022, 9:13 AM
Copy code
class A {
    fun test() {
        println()
    }
}
Does it print empty line or
A
?
e

Eric Ou

06/29/2022, 9:13 AM
I see... so in this case you can't print an empty line without using the full qualified name...
d

dmitriy.novozhilov

06/29/2022, 9:14 AM
Yep
e

Eric Ou

06/29/2022, 9:14 AM
You could just call it something else
Like
printObject
or something
or
printAndReturn
d

dmitriy.novozhilov

06/29/2022, 9:15 AM
Do you have any usecases except debugging?
y

Youssef Shoaib [MOD]

06/29/2022, 9:16 AM
There's already an idiomatic pattern to do this btw:
Copy code
objectOrLongExpression.also(::println).continueMethodChain()
In general,
also
is used to perform some side effect and then continue a method chain.
8
e

Eric Ou

06/29/2022, 9:16 AM
hmm I never thought about it that way
But yeah, not really a usecase outside of debugging I would say
I mean the usage of println is kinda limited in the first place right?
s

Starr

06/29/2022, 2:07 PM
there's also the IntelliJ suffix template stuff
2 Views