The .( Operator, explained


#1

I searched around the web and inside the Kotlin Documentations but had a hard time trying to understand what the simple dot after a class is supposed to achieve.

For example in this snippet, we see List<String>.() and it works fine. But without the .() the compiler is left wondering what I am trying to achieve.

    val isEmptyStringList: List<String>.() -> Boolean = List<String>::isEmpty

By the nature of this operator being just a “dot” it is very hard trying to find resources on it be it from Google or specialised search engines like symbolhound.

And if you think I should’ve found those resources by myself, please point me to how one can find such things.


#2

http://kotlinlang.org/docs/reference/lambdas.html#function-literals-with-receiver


#3

Thank you!


#4

Here’s a post that explains the dot operator: https://blog.jetbrains.com/kotlin/2013/04/the-dot-operator/

If you get confused, check the date the post was published :wink:


#5

:smiley:
Funny enough I got to this article while trying to find the real meaning behind the .( it didn’t help me at all but made me chuckle.