In the code the removeSelf function is not allowed to access the outer class if included in the AstMutator interface but if it is written as an extension function it is. Is there an other (better) way to do this? Is this a proper use case for an extension function? Anyway I think kotlin is a really fun language to program in.
Last active
August 29, 2019 18:14
-
-
Save raldone01/aa3835d5e7bb05844f658dc459ea7277 to your computer and use it in GitHub Desktop.
I like extension functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Parent { | |
/** | |
* This property is null when this isn't attached to anything. | |
*/ | |
val parent: Parent? | |
val children: List<Parent> | |
/** | |
* @throws NoMutationAllowedException | |
*/ | |
val mutate: AstMutator | |
interface AstMutator : MutableList<Parent> | |
fun AstMutator.removeSelf() { | |
parent?.mutate?.remove(this@Parent) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment