small matrix improvements

This commit is contained in:
InsanusMokrassar 2023-11-29 20:33:06 +06:00
parent 915bac64b1
commit 9b30c3a155
2 changed files with 7 additions and 3 deletions

View File

@ -1,12 +1,15 @@
package dev.inmo.micro_utils.matrix
class MatrixBuilder<T> {
open class MatrixBuilder<T> {
private val mutMatrix: MutableList<List<T>> = ArrayList()
val matrix: Matrix<T>
get() = mutMatrix
fun row(t: List<T>) = mutMatrix.add(t)
fun add(t: List<T>) = mutMatrix.add(t)
operator fun List<T>.unaryPlus() = row(this)
operator fun plus(t: List<T>) = add(t)
operator fun T.unaryPlus() = add(listOf(this))
}
fun <T> MatrixBuilder<T>.row(block: RowBuilder<T>.() -> Unit) = +RowBuilder<T>().also(block).row

View File

@ -1,12 +1,13 @@
package dev.inmo.micro_utils.matrix
class RowBuilder<T> {
open class RowBuilder<T> {
private val mutRow: MutableList<T> = ArrayList()
val row: Row<T>
get() = mutRow
fun column(t: T) = mutRow.add(t)
fun add(t: T) = mutRow.add(t)
operator fun T.unaryPlus() = column(this)
fun column(t: T) = mutRow.add(t)
}
fun <T> row(block: RowBuilder<T>.() -> Unit): List<T> = RowBuilder<T>().also(block).row