What is an extension function?
Function extensions in Kotlin are one of the most interesting features in the universe of possibilities that Kotlin provides. We can say that a function extension will allow us to extend the functionality of a class that already exists. This highlights that function extensions allow us to increase the capabilities of the classes that we already have in our code so that we don’t have to modify them.
Imagine going to a restaurant where the chef has already prepared a set menu with fixed dishes – pasta, pizza, and salads. You love the pasta but wish it came with a special sauce that’s not on the menu. You can’t ask the restaurant to change the pasta for everyone, but you can bring your own special sauce and pour it on top of your dish without changing the restaurant’s menu. The pasta remains the same for other customers, but for you, it has an extra flavor because of the sauce you’ve added.
This is similar...