diff --git a/CHANGELOG.md b/CHANGELOG.md index 977e9eaf695..26b64ef203b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 0.4.25 + +* `Matrix`: + * Subproject has been created + ## 0.4.24 * `Versions`: diff --git a/gradle.properties b/gradle.properties index cf79ad930cc..06b74f396c6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/matrix/build.gradle b/matrix/build.gradle new file mode 100644 index 00000000000..7c54502f100 --- /dev/null +++ b/matrix/build.gradle @@ -0,0 +1,7 @@ +plugins { + id "org.jetbrains.kotlin.multiplatform" + id "org.jetbrains.kotlin.plugin.serialization" + id "com.android.library" +} + +apply from: "$mppProjectWithSerializationPresetPath" diff --git a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Matrix.kt b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Matrix.kt new file mode 100644 index 00000000000..3d757d42cb3 --- /dev/null +++ b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Matrix.kt @@ -0,0 +1,3 @@ +package dev.inmo.micro_utils.matrix + +typealias Matrix = List> diff --git a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/MatrixBuilder.kt b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/MatrixBuilder.kt new file mode 100644 index 00000000000..6c5292f47ee --- /dev/null +++ b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/MatrixBuilder.kt @@ -0,0 +1,13 @@ +package dev.inmo.micro_utils.matrix + +class MatrixBuilder { + private val mutMatrix: MutableList> = ArrayList() + val matrix: Matrix + get() = mutMatrix + + fun row(t: List) = mutMatrix.add(t) + operator fun List.unaryPlus() = row(this) +} + +fun MatrixBuilder.row(block: RowBuilder.() -> Unit) = +RowBuilder().also(block).row +fun MatrixBuilder.row(vararg elements: T) = +elements.toList() diff --git a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/MatrixFactories.kt b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/MatrixFactories.kt new file mode 100644 index 00000000000..045da40645d --- /dev/null +++ b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/MatrixFactories.kt @@ -0,0 +1,17 @@ +package dev.inmo.micro_utils.matrix + +fun matrix(block: MatrixBuilder.() -> Unit): Matrix { + return MatrixBuilder().also(block).matrix +} + +fun flatMatrix(block: RowBuilder.() -> Unit): Matrix { + return MatrixBuilder().apply { + row(block) + }.matrix +} + +fun flatMatrix(vararg elements: T): Matrix { + return MatrixBuilder().apply { + row { elements.forEach { +it } } + }.matrix +} diff --git a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Row.kt b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Row.kt new file mode 100644 index 00000000000..701457d91b4 --- /dev/null +++ b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Row.kt @@ -0,0 +1,3 @@ +package dev.inmo.micro_utils.matrix + +typealias Row = List diff --git a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/RowBuilder.kt b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/RowBuilder.kt new file mode 100644 index 00000000000..f79a71ea2c5 --- /dev/null +++ b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/RowBuilder.kt @@ -0,0 +1,14 @@ +package dev.inmo.micro_utils.matrix + +class RowBuilder { + private val mutRow: MutableList = ArrayList() + val row: Row + get() = mutRow + + fun column(t: T) = mutRow.add(t) + operator fun T.unaryPlus() = column(this) +} + +fun row(block: RowBuilder.() -> Unit): List = RowBuilder().also(block).row +fun RowBuilder.columns(elements: List) = elements.forEach(::column) +fun RowBuilder.columns(vararg elements: T) = elements.forEach(::column) diff --git a/matrix/src/commonTest/kotlin/dev/inmo/micro_utils/matrix/SimpleTest.kt b/matrix/src/commonTest/kotlin/dev/inmo/micro_utils/matrix/SimpleTest.kt new file mode 100644 index 00000000000..17416d2fe77 --- /dev/null +++ b/matrix/src/commonTest/kotlin/dev/inmo/micro_utils/matrix/SimpleTest.kt @@ -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 { + row(1, 2, 3) + row(4, 5, 6) + } + + val fromMatrixWithColumnsVarargs = matrix { + row { + columns(1, 2, 3) + } + row { + columns(4, 5, 6) + } + } + + val fromMatrixWithSimpleAdd = matrix { + row { + column(1) + column(2) + column(3) + } + row { + column(4) + column(5) + column(6) + } + } + + assertEquals(expected, fromMatrixWithVarargs) + assertEquals(expected, fromMatrixWithColumnsVarargs) + assertEquals(expected, fromMatrixWithSimpleAdd) + } +} \ No newline at end of file diff --git a/matrix/src/main/AndroidManifest.xml b/matrix/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..90fc16dfe66 --- /dev/null +++ b/matrix/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 7b43068aaa5..ea4cd8a08b3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,6 +2,7 @@ rootProject.name='micro_utils' String[] includes = [ ":common", + ":matrix", ":crypto", ":selector:common", ":pagination:common",