mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-18 14:47:15 +00:00
small matrix improvements
This commit is contained in:
parent
915bac64b1
commit
9b30c3a155
@ -1,12 +1,15 @@
|
|||||||
package dev.inmo.micro_utils.matrix
|
package dev.inmo.micro_utils.matrix
|
||||||
|
|
||||||
class MatrixBuilder<T> {
|
open class MatrixBuilder<T> {
|
||||||
private val mutMatrix: MutableList<List<T>> = ArrayList()
|
private val mutMatrix: MutableList<List<T>> = ArrayList()
|
||||||
val matrix: Matrix<T>
|
val matrix: Matrix<T>
|
||||||
get() = mutMatrix
|
get() = mutMatrix
|
||||||
|
|
||||||
fun row(t: List<T>) = mutMatrix.add(t)
|
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 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
|
fun <T> MatrixBuilder<T>.row(block: RowBuilder<T>.() -> Unit) = +RowBuilder<T>().also(block).row
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package dev.inmo.micro_utils.matrix
|
package dev.inmo.micro_utils.matrix
|
||||||
|
|
||||||
class RowBuilder<T> {
|
open class RowBuilder<T> {
|
||||||
private val mutRow: MutableList<T> = ArrayList()
|
private val mutRow: MutableList<T> = ArrayList()
|
||||||
val row: Row<T>
|
val row: Row<T>
|
||||||
get() = mutRow
|
get() = mutRow
|
||||||
|
|
||||||
fun column(t: T) = mutRow.add(t)
|
fun add(t: T) = mutRow.add(t)
|
||||||
operator fun T.unaryPlus() = column(this)
|
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
|
fun <T> row(block: RowBuilder<T>.() -> Unit): List<T> = RowBuilder<T>().also(block).row
|
||||||
|
Loading…
Reference in New Issue
Block a user