mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-17 22:03:50 +00:00
commit
4322ffdb0a
@ -1,5 +1,10 @@
|
||||
# Changelog
|
||||
|
||||
## 0.4.25
|
||||
|
||||
* `Matrix`:
|
||||
* Subproject has been created
|
||||
|
||||
## 0.4.24
|
||||
|
||||
* `Versions`:
|
||||
|
@ -44,5 +44,5 @@ dokka_version=1.4.20
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.4.24
|
||||
android_code_version=28
|
||||
version=0.4.25
|
||||
android_code_version=29
|
||||
|
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,13 @@
|
||||
package dev.inmo.micro_utils.matrix
|
||||
|
||||
class MatrixBuilder<T> {
|
||||
private val mutMatrix: MutableList<List<T>> = ArrayList()
|
||||
val matrix: Matrix<T>
|
||||
get() = mutMatrix
|
||||
|
||||
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()
|
@ -0,0 +1,17 @@
|
||||
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
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
package dev.inmo.micro_utils.matrix
|
||||
|
||||
typealias Row<T> = List<T>
|
@ -0,0 +1,14 @@
|
||||
package dev.inmo.micro_utils.matrix
|
||||
|
||||
class RowBuilder<T> {
|
||||
private val mutRow: MutableList<T> = ArrayList()
|
||||
val row: Row<T>
|
||||
get() = mutRow
|
||||
|
||||
fun column(t: T) = mutRow.add(t)
|
||||
operator fun T.unaryPlus() = column(this)
|
||||
}
|
||||
|
||||
fun <T> row(block: RowBuilder<T>.() -> Unit): List<T> = RowBuilder<T>().also(block).row
|
||||
fun <T> RowBuilder<T>.columns(elements: List<T>) = elements.forEach(::column)
|
||||
fun <T> RowBuilder<T>.columns(vararg elements: T) = elements.forEach(::column)
|
@ -0,0 +1,45 @@
|
||||
package dev.inmo.micro_utils.matrix
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class SimpleTest {
|
||||
@Test
|
||||
fun simpleTest() {
|
||||
val expected = listOf(
|
||||
listOf(1, 2, 3),
|
||||
listOf(4, 5, 6)
|
||||
)
|
||||
|
||||
val fromMatrixWithVarargs = matrix<Int> {
|
||||
row(1, 2, 3)
|
||||
row(4, 5, 6)
|
||||
}
|
||||
|
||||
val fromMatrixWithColumnsVarargs = matrix<Int> {
|
||||
row {
|
||||
columns(1, 2, 3)
|
||||
}
|
||||
row {
|
||||
columns(4, 5, 6)
|
||||
}
|
||||
}
|
||||
|
||||
val fromMatrixWithSimpleAdd = matrix<Int> {
|
||||
row {
|
||||
column(1)
|
||||
column(2)
|
||||
column(3)
|
||||
}
|
||||
row {
|
||||
column(4)
|
||||
column(5)
|
||||
column(6)
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(expected, fromMatrixWithVarargs)
|
||||
assertEquals(expected, fromMatrixWithColumnsVarargs)
|
||||
assertEquals(expected, fromMatrixWithSimpleAdd)
|
||||
}
|
||||
}
|
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 = [
|
||||
":common",
|
||||
":matrix",
|
||||
":crypto",
|
||||
":selector:common",
|
||||
":pagination:common",
|
||||
|
Loading…
Reference in New Issue
Block a user