diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml
index 7974e89..6cca5ca 100644
--- a/.github/workflows/actions.yml
+++ b/.github/workflows/actions.yml
@@ -30,4 +30,7 @@ jobs:
- name: Publish package
run: ./gradlew publish
env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
+ ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
+ ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_IN_MEMORY_KEY }}
+ ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_IN_MEMORY_KEY_PASSWORD }}
diff --git a/.idea/artifacts/kotlin_parallel_operations_js_1_6_0.xml b/.idea/artifacts/kotlin_parallel_operations_js_1_6_0.xml
index 552a8e0..cbb9936 100644
--- a/.idea/artifacts/kotlin_parallel_operations_js_1_6_0.xml
+++ b/.idea/artifacts/kotlin_parallel_operations_js_1_6_0.xml
@@ -1,8 +1,6 @@
$PROJECT_DIR$/build/libs
-
-
-
+
\ No newline at end of file
diff --git a/.idea/artifacts/kotlin_parallel_operations_jvm_1_6_0.xml b/.idea/artifacts/kotlin_parallel_operations_jvm_1_6_0.xml
index 668e801..8f59da4 100644
--- a/.idea/artifacts/kotlin_parallel_operations_jvm_1_6_0.xml
+++ b/.idea/artifacts/kotlin_parallel_operations_jvm_1_6_0.xml
@@ -1,8 +1,6 @@
$PROJECT_DIR$/build/libs
-
-
-
+
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 919ce1f..f5cb871 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -1,7 +1,13 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
index a55e7a1..6e6eec1 100644
--- a/.idea/codeStyles/codeStyleConfig.xml
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -1,5 +1,6 @@
+
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..01f8181
--- /dev/null
+++ b/README.md
@@ -0,0 +1,41 @@
+# Parallel Operations for Kotlin
+Parallel *map*, *reduce*, and various indexed and in-place operations on collections for Kotlin using coroutines.
+
+The parallel *map* implementation is called *.mapParallel()*. It is implemented like this.
+```kotlin
+suspend fun Iterable.mapParallel(transform: (T) -> R): List = coroutineScope {
+ map { async { transform(it) } }.map { it.await() }
+}
+```
+
+Example of using the parallel *map* operation.
+```kotlin
+fun showCase() {
+ val list = listOf(1,2,3)
+ runBlocking(Dispatchers.Default) {
+ var mappedList = list.mapParallel { it * 2 } // Results in [2,4,6]
+ }
+}
+```
+
+There is also the parallel *reduce* operation with chunked variations, which can be used to perform **associative** operations on a collection, like *sum*.
+
+**Note:** If you want to achieve multithreading, make sure to run the coroutine with the Default dispatcher.
+
+## Chunked operations
+Chunked operations improve performance since they split the collection into just a couple of segments,
+which are processed each by a single thread. That benefits from data locality and lesser thread management.
+It is particularly useful (pretty much needed for operations like sum) in the reduce operation when using multithreading,
+since each thread takes one chunk that it reduces on its own. After all coroutines finish, their results are then reduced again to the final result.
+
+## Gradle
+The library is published in the Maven Central repository.
+Include this line in your module build.gradle file.
+```gradle
+dependencies {
+ implementation("io.github.cvb941:kotlin-parallel-operations:2.0.0")
+}
+```
+
+## Future
+In the future, I would like other transformation functions to be implemented.
diff --git a/build.gradle.kts b/build.gradle.kts
index 82010dd..28d1c68 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,13 +1,14 @@
+import com.vanniktech.maven.publish.SonatypeHost
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
plugins {
kotlin("multiplatform") version "1.9.23"
id("org.jetbrains.kotlinx.benchmark") version "0.4.10"
id("org.jetbrains.kotlin.plugin.allopen") version "1.9.23"
- id("maven-publish")
+ id("com.vanniktech.maven.publish") version "0.28.0"
}
-group = "net.kusik"
+group = "io.github.cvb941"
version = "2.0.0"
repositories {
@@ -90,15 +91,34 @@ allOpen {
annotation("org.openjdk.jmh.annotations.State")
}
-publishing {
- repositories {
- maven {
- name = "GitHubPackages"
- url = uri("https://maven.pkg.github.com/cvb941/kotlin-parallel-operations")
- credentials {
- username = project.findProperty("gpr.user")?.toString() ?: System.getenv("GITHUB_ACTOR")
- password = project.findProperty("gpr.key")?.toString() ?: System.getenv("GITHUB_TOKEN")
+mavenPublishing {
+ publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true)
+
+ signAllPublications()
+
+ pom {
+ name.set("Parallel Operations")
+ description.set("Parallel map, reduce and more using coroutines in Kotlin.")
+ inceptionYear.set("2019")
+ url.set("https://github.com/cvb941/kotlin-parallel-operations/")
+ licenses {
+ license {
+ name.set("MIT License")
+ url.set("https://opensource.org/licenses/MIT")
+ distribution.set("repo")
}
}
+ developers {
+ developer {
+ id.set("cvb941")
+ name.set("Lukas Kusik")
+ url.set("https://github.com/cvb941/")
+ }
+ }
+ scm {
+ url.set("https://github.com/cvb941/kotlin-parallel-operations/")
+ connection.set("scm:git:git://github.com/cvb941/kotlin-parallel-operations.git")
+ developerConnection.set("scm:git:ssh://git@github.com/cvb941/kotlin-parallel-operations.git")
+ }
}
}