Skip to content

Instantly share code, notes, and snippets.

@raldone01
Last active August 29, 2019 18:14
Show Gist options
  • Save raldone01/aa3835d5e7bb05844f658dc459ea7277 to your computer and use it in GitHub Desktop.
Save raldone01/aa3835d5e7bb05844f658dc459ea7277 to your computer and use it in GitHub Desktop.
I like extension functions

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.

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