Merge pull request #46 from InsanusMokrassar/0.4.25

0.4.25
This commit is contained in:
InsanusMokrassar 2021-02-11 15:12:39 +06:00 committed by GitHub
commit 4322ffdb0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 111 additions and 2 deletions

View File

@ -1,5 +1,10 @@
# Changelog # Changelog
## 0.4.25
* `Matrix`:
* Subproject has been created
## 0.4.24 ## 0.4.24
* `Versions`: * `Versions`:

View File

@ -44,5 +44,5 @@ dokka_version=1.4.20
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.4.24 version=0.4.25
android_code_version=28 android_code_version=29

7
matrix/build.gradle Normal file
View File

@ -0,0 +1,7 @@
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization"
id "com.android.library"
}
apply from: "$mppProjectWithSerializationPresetPath"

View File

@ -0,0 +1,3 @@
package dev.inmo.micro_utils.matrix
typealias Matrix<T> = List<Row<T>>

View File

@ -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()

View File

@ -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
}

View File

@ -0,0 +1,3 @@
package dev.inmo.micro_utils.matrix
typealias Row<T> = List<T>

View File

@ -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)

View File

@ -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)
}
}

View File

@ -0,0 +1 @@
<manifest package="dev.inmo.micro_utils.matrix"/>

View File

@ -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",