Skip to content

Instantly share code, notes, and snippets.

@latant
Created March 26, 2020 15:54
Show Gist options
  • Save latant/08623e192d1b5b9d16055978f8fdc566 to your computer and use it in GitHub Desktop.
Save latant/08623e192d1b5b9d16055978f8fdc566 to your computer and use it in GitHub Desktop.
Simple persistent (single-linked) list implemented with Kotlin
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