Skip to content

Instantly share code, notes, and snippets.

@AndyBowes
Created August 2, 2017 11:20
Show Gist options
  • Save AndyBowes/b588c271c624a3ed94a11a79e9d829a1 to your computer and use it in GitHub Desktop.
Save AndyBowes/b588c271c624a3ed94a11a79e9d829a1 to your computer and use it in GitHub Desktop.
Kotlin TreeNode (Draft)
fun idSequence(seed:Int=0) : Sequence<Int>{
return generateSequence(seed,{it + 1})
}
class TreeNode<T>(val id: T){
val childNodes = mutableListOf<TreeNode<T>>()
fun addChild(node: TreeNode<T>) = childNodes.add(node)
fun removeChild(node: TreeNode<T>) = childNodes.remove(node)
fun children() = childNodes.asIterable()
}
fun main(args: Array<String>) {
println(idSequence(1).take(10).toList())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment