Pihentagy
12/19/2025, 5:15 PMKlitos Kyriacou
12/19/2025, 5:29 PMreturn parser.use {
it.asSequence()
.drop(1)
.map {...}
}James Richardson
12/19/2025, 6:41 PMPihentagy
12/19/2025, 6:42 PMPihentagy
12/19/2025, 6:43 PMJames Richardson
12/19/2025, 6:51 PMMichael Krussel
12/19/2025, 6:57 PMsequence function. You would open and use the parser inside the lambda. Something like
sequence {
builder.parse.use { emitAll(it) }
}
Could make it an extension function on the builder class.hfhbd
12/19/2025, 7:59 PMWout Werkman
12/20/2025, 11:11 AM.first(). Flows don't have this footgun, and make resource handling a lot easier.Wout Werkman
12/20/2025, 11:13 AMsequence { try { yield(1); yield(1) } finally { println("Finished") } }.first() will not print "Finished" (Sorry, on phone)Pihentagy
12/20/2025, 11:15 AMWout Werkman
12/20/2025, 11:16 AMPihentagy
12/20/2025, 11:19 AMWout Werkman
12/20/2025, 11:24 AMPihentagy
12/20/2025, 11:25 AMWout Werkman
12/20/2025, 11:27 AMBut flows are not more heavyweight, right?Correct. I don't have numbers but from naive assumption the sequence builder is significantlt more expensive than the flow builder. In my humble opinion people associate
suspend too strongly to something complex.
Anyhow, I don't mean to hijack the thread.Pihentagy
12/20/2025, 11:30 AMWout Werkman
12/20/2025, 5:23 PMWout Werkman
12/20/2025, 5:24 PMPihentagy
12/20/2025, 7:14 PMKlitos Kyriacou
12/21/2025, 4:28 PMCSVParser.close seems to just close the associated reader. So a workaround is to define the above function without closing (i.e. keep your function as it is in your initial post) and close the reader in the caller of your function. This is not generally applicable, but just for CSVParser.Michael Krussel
12/21/2025, 5:16 PMfinally doesn't get run. I would have assumed the second yield would throw a CancellationException. Good to know about that.