<https://stackoverflow.com/questions/65397653/is-t...
# announcements
n
don't think so
while Kotlin has a decent amount of functional programming things, I think this is even further into LISP territory, which is probably underrepresented
did you want help with the implementation or no?
d
My current stab is
Copy code
private fun <T> Sequence<T>.destruct(): Pair<T, Sequence<T>>? {
    val iterator = this.iterator()
    return if (!iterator.hasNext())
        null
    else
        iterator.next() to Sequence { iterator }
}
n
yeah mine's basically the same
d
I was a bit surprised not to find it, which makes me wonder if it is a bad idea, but I need to take the header of a CSV list in a non-terminal sort of a way
n
I'd recommend using a CSV parsing library there, anyway
d
It’s just for fun, I certainly don’t want to be dealing with all those horrible escaping rules!
Thanks for the help - paste your answer into Stack Overflow for Internet points!
n
fair enough 🙂
oh, someone else posted a clever one-liner
though it does technically create two iterators...
I guess it returns the same iterator twice actually? anyway
d
Hmm, I think it will fail if the sequence is constrainOnce, as both firstOrNull and drop are terminal