updates in matrix

This commit is contained in:
2021-02-11 15:05:11 +06:00
parent a3cabd7a9e
commit d41c3c2de4
4 changed files with 55 additions and 16 deletions

View File

@@ -5,6 +5,9 @@ class MatrixBuilder<T> {
val matrix: Matrix<T>
get() = mutMatrix
fun add(t: List<T>) = mutMatrix.add(t)
operator fun plus(t: List<T>) = add(t)
fun row(t: List<T>) = mutMatrix.add(t)
operator fun List<T>.unaryPlus() = row(this)
}
fun <T> MatrixBuilder<T>.row(block: RowBuilder<T>.() -> Unit) = +RowBuilder<T>().also(block).row
fun <T> MatrixBuilder<T>.row(vararg elements: T) = +elements.toList()

View File

@@ -15,17 +15,3 @@ fun <T> flatMatrix(vararg elements: T): Matrix<T> {
row { elements.forEach { +it } }
}.matrix
}
fun <T> row(block: RowBuilder<T>.() -> Unit): List<T> {
return RowBuilder<T>().also(block).row
}
fun <T> MatrixBuilder<T>.row(block: RowBuilder<T>.() -> Unit) {
add(RowBuilder<T>().also(block).row)
}
fun <T> MatrixBuilder<T>.row(vararg elements: T) {
add(elements.toList())
}
operator fun <T> RowBuilder<T>.plus(t: T) = add(t)

View File

@@ -8,3 +8,8 @@ class RowBuilder<T> {
fun add(t: T) = mutRow.add(t)
operator fun T.unaryPlus() = add(this)
}
fun <T> row(block: RowBuilder<T>.() -> Unit): List<T> = RowBuilder<T>().also(block).row
fun <T> RowBuilder<T>.column(element: T) = +element
fun <T> RowBuilder<T>.columns(elements: List<T>) = elements.forEach(::column)
fun <T> RowBuilder<T>.columns(vararg elements: T) = elements.forEach(::column)