re The Kotlin example fun String.mutate():, extending the builtin String class.
This a favorite example, because in Java builtin classes are sealed/closed, and in Kotlin and many other langs they are open, so you can monkeypatch those system classes. <a href="https://kotlinlang.org/docs/sealed-classes.html#sealed-classes-and-when-expression" rel="nofollow noreferrer">https://kotlinlang.org/docs/sealed-classes.html#sealed-class...</a><p>A cool new feature or a bad mis-feature?<p>Closed classes offer tremendous compile-time safety guarantees and optimization possibilities. with open classes you have to check inheritance on each and every call at run-time, with sealed classes you can easily inline them. A much cooler feature than open classes.<p>Larry Wall was so angry about closed java classes that he wanted them open and slow. On the other hand, Damian Conway, the perl6 designer, wanted them closed by default. You have to look at the current raku design if they are still open or closed. One of the many reasons why raku is so slow.