Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
folding cursors all day
inline fun <T> Cursor.fold(zero: T, f: (Cursor, T) -> T): T =
if (moveToFirst()) {
var accum = zero
while (moveToNext()) {
accum = f(this, accum)
} else zero
inline fun <T> Cursor.forEachRow(f: (Cursor) -> T): Unit =
fold(Unit) { c, x -> f(c) }
inline fun <T> (Cursor) -> T): List<T> =
fold(ArrayList<T>(count)) { c, list -> list.apply { add(f(c)) } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.