Created
August 2, 2017 11:20
-
-
Save AndyBowes/b588c271c624a3ed94a11a79e9d829a1 to your computer and use it in GitHub Desktop.
Kotlin TreeNode (Draft)
This file contains hidden or 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
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