rocketraman
01/04/2017, 6:42 PMprotected fun typedValue(untypedValue: Map<String, Any?>?): T? =
mapper.convertValue(untypedValue, klass.java)
protected fun typedList(untypedIterable: Iterable<Map<String, Any?>>): List<T> =
when(untypedIterable) {
is Cursor<Map<String, Any?>> -> untypedIterable.use { it.map { typedValue(it)!! } }
else -> untypedIterable.map { typedValue(it)!! }
}
protected fun typedSequence(untypedIterable: Iterable<Map<String, Any?>>): Sequence<T> =
when(untypedIterable) {
is Cursor<Map<String, Any?>> -> untypedIterable.use {
it.iterator().asSequence().map { typedValue(it)!! }
}
else -> error("Expected cursor")
}