Hi, is there any convention used in kotlin to deci...
# getting-started
Hi, is there any convention used in kotlin to decide where to place extension functions?
👍 1
In most cases, you define extensions on the top level, directly under packages:
https://kotlinlang.org/docs/extensions.html#scope-of-extensions In the stdlib, it is pretty common to see a plural version of the extension receiver as the filename, like
for extensions of the
type. https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/src/kotlin/text/Strings.kt Making private extension functions in a file can also be nice if you have something that isn’t general purpose and you just want to make something read a little cleaner in the context of a file.
I like to create a file named Extensions.kt for any extensions that I may need throughout the app to make them easy to find. For KMM projects, I've found that naming the file {Platform}Extensions works well so I can find each one easier.
Thanks for the answers