Created
March 26, 2020 15:54
-
-
Save latant/08623e192d1b5b9d16055978f8fdc566 to your computer and use it in GitHub Desktop.
Simple persistent (single-linked) list implemented with Kotlin
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
package core | |
open class PList<T>(val value: T, val next: PList<T>?) : Iterable<T> { | |
override fun iterator() = object : Iterator<T> { | |
var PList: PList<T>? = this@PList | |
override fun hasNext() = PList != null | |
override fun next() = PList!!.value.also { PList = PList!!.next } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment