Remove redundant cast in tables

This commit is contained in:
Alexander Nozik 2020-03-15 13:45:24 +03:00
parent b78fc2e7d7
commit bc8878da48

View File

@ -134,14 +134,11 @@ private fun Output.writeValue(value: Value, width: Int, left: Boolean = true) {
* Write rows without header to the output * Write rows without header to the output
*/ */
suspend fun Output.writeRows(rows: Rows<Value>) { suspend fun Output.writeRows(rows: Rows<Value>) {
@Suppress("UNCHECKED_CAST") val header = rows.header.map { val widths: List<Int> = rows.header.map {
if (it.type != Value::class) error("Expected Value column, but found ${it.type}") else (it as ColumnHeader<Value>)
}
val widths: List<Int> = header.map {
it.textWidth it.textWidth
} }
rows.rowFlow().collect { row -> rows.rowFlow().collect { row ->
header.forEachIndexed { index, columnHeader -> rows.header.forEachIndexed { index, columnHeader ->
writeValue(row[columnHeader] ?: Null, widths[index]) writeValue(row[columnHeader] ?: Null, widths[index])
} }
writeUtf8String("\r\n") writeUtf8String("\r\n")