mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 16:23:50 +00:00
add matrix
This commit is contained in:
parent
3dde486126
commit
a3cabd7a9e
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
## 0.4.25
|
## 0.4.25
|
||||||
|
|
||||||
|
* `Matrix`:
|
||||||
|
* Subproject has been created
|
||||||
|
|
||||||
## 0.4.24
|
## 0.4.24
|
||||||
|
|
||||||
* `Versions`:
|
* `Versions`:
|
||||||
|
7
matrix/build.gradle
Normal file
7
matrix/build.gradle
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
|
id "org.jetbrains.kotlin.plugin.serialization"
|
||||||
|
id "com.android.library"
|
||||||
|
}
|
||||||
|
|
||||||
|
apply from: "$mppProjectWithSerializationPresetPath"
|
@ -0,0 +1,3 @@
|
|||||||
|
package dev.inmo.micro_utils.matrix
|
||||||
|
|
||||||
|
typealias Matrix<T> = List<Row<T>>
|
@ -0,0 +1,10 @@
|
|||||||
|
package dev.inmo.micro_utils.matrix
|
||||||
|
|
||||||
|
class MatrixBuilder<T> {
|
||||||
|
private val mutMatrix: MutableList<List<T>> = ArrayList()
|
||||||
|
val matrix: Matrix<T>
|
||||||
|
get() = mutMatrix
|
||||||
|
|
||||||
|
fun add(t: List<T>) = mutMatrix.add(t)
|
||||||
|
operator fun plus(t: List<T>) = add(t)
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
package dev.inmo.micro_utils.matrix
|
||||||
|
|
||||||
|
typealias Row<T> = List<T>
|
@ -0,0 +1,10 @@
|
|||||||
|
package dev.inmo.micro_utils.matrix
|
||||||
|
|
||||||
|
class RowBuilder<T> {
|
||||||
|
private val mutRow: MutableList<T> = ArrayList()
|
||||||
|
val row: Row<T>
|
||||||
|
get() = mutRow
|
||||||
|
|
||||||
|
fun add(t: T) = mutRow.add(t)
|
||||||
|
operator fun T.unaryPlus() = add(this)
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package dev.inmo.micro_utils.matrix
|
||||||
|
|
||||||
|
fun <T> matrix(block: MatrixBuilder<T>.() -> Unit): Matrix<T> {
|
||||||
|
return MatrixBuilder<T>().also(block).matrix
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> flatMatrix(block: RowBuilder<T>.() -> Unit): Matrix<T> {
|
||||||
|
return MatrixBuilder<T>().apply {
|
||||||
|
row(block)
|
||||||
|
}.matrix
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> flatMatrix(vararg elements: T): Matrix<T> {
|
||||||
|
return MatrixBuilder<T>().apply {
|
||||||
|
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)
|
1
matrix/src/main/AndroidManifest.xml
Normal file
1
matrix/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1 @@
|
|||||||
|
<manifest package="dev.inmo.micro_utils.matrix"/>
|
@ -2,6 +2,7 @@ rootProject.name='micro_utils'
|
|||||||
|
|
||||||
String[] includes = [
|
String[] includes = [
|
||||||
":common",
|
":common",
|
||||||
|
":matrix",
|
||||||
":crypto",
|
":crypto",
|
||||||
":selector:common",
|
":selector:common",
|
||||||
":pagination:common",
|
":pagination:common",
|
||||||
|
Loading…
Reference in New Issue
Block a user