Skip to content

Update to Kotlin RC3, and Arrow 2 Alpha 1 #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ on:
branches:
- main

env:
JAVA_OPTS: -Xms512m -Xmx1024m
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.configureondemand=true -Dorg.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8"

jobs:
check:
runs-on: ubuntu-latest
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/githubpages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
release:
types: [published]

env:
GRADLE_OPTS: -Dorg.gradle.daemon=false -Dorg.gradle.kotlin.dsl.internal.io.timeout=120000 -Dorg.gradle.jvmargs="-Xmx5g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8"

jobs:
githubpages:
runs-on: ubuntu-latest
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ on:
type: string

env:
JAVA_OPTS: -Xms1g -Xmx3g
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.configureondemand=true -Dorg.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8"
ORG_GRADLE_PROJECT_mavenCentralUsername: '${{ secrets.SONATYPE_USER }}'
ORG_GRADLE_PROJECT_mavenCentralPassword: '${{ secrets.SONATYPE_PWD }}'
ORG_GRADLE_PROJECT_signingInMemoryKeyId: '${{ secrets.SIGNING_KEY_ID }}'
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Pull Request"

on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 11

- name: Build
uses: gradle/gradle-build-action@v2
with:
arguments: build
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,5 @@ kotlin-js-store

# End of https://www.toptal.com/developers/gitignore/api/intellij+all,kotlin,gradle,macos

gradle-build-scan.txt
gradle-build-scan.txt
.kotlin
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ In the example below we select the _employees_ `JsonArray`,
and then we select _every_ `JsonElement` in the `JsonArray`.
We then _select_ the _name_ out of _every_ `JsonElement`.

Instead of `Optional<JsonElement, String>` it now returns `Every<JsonElement, String>`,
Instead of `Optional<JsonElement, String>` it now returns `Traversal<JsonElement, String>`,
since we selected _many properties_ instead of a _single property_.

Just like before we can apply a function to it using _modify_,
Expand All @@ -118,7 +118,7 @@ fun main(): Unit {
-->
```kotlin
val json: JsonElement = Json.decodeFromString(JSON_STRING)
val employeesName: Every<JsonElement, String> = JsonPath.select("employees").every.select("name").string
val employeesName: Traversal<JsonElement, String> = JsonPath.select("employees").every.select("name").string
val res: JsonElement = employeesName.modify(json, String::uppercase).also(::println)
employeesName.getAll(res).also(::println)
```
Expand All @@ -137,7 +137,7 @@ Like before, below we select the _employees_ `JsonArray`,
and then we select _every_ `JsonElement` in the `JsonArray`.
We then _select_ the _name_ out of _every_ `JsonElement`.

Again, instead of `Optional<JsonElement, String>` it now returns `Every<JsonElement, String>`,
Again, instead of `Optional<JsonElement, String>` it now returns `Traversal<JsonElement, String>`,
since we selected _many properties_ instead of a _single property_.

You can then, apply a function to it using _modify_ like before.
Expand All @@ -151,13 +151,13 @@ fun main(): Unit {
-->
```kotlin
val json: JsonElement = Json.decodeFromString(JSON_STRING)
val employeesName: Every<JsonElement, String> = JsonPath.pathEvery("employees.*.name").string
val employeesName: Traversal<JsonElement, String> = JsonPath.pathEvery("employees.*.name").string
val res: JsonElement = employeesName.modify(json, String::uppercase).also(::println)
employeesName.getAll(res).also(::println)
```
> You can get the full code [here](src/jvmTest/kotlin/example/example-readme-03.kt).
> You can get the full code [here](src/jvmTest/kotlin/example/example-readme-04.kt).

```text
{"name":"Arrow","address":{"city":"Functional Town","street":{"number":1337,"name":"Functional street"}},"employees":[{"name":"JOHN","lastName":"doe"},{"name":"JANE","lastName":"doe"}]}
[JOHN, JANE]
```
```
59 changes: 41 additions & 18 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@ import kotlinx.knit.KnitPluginExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
import kotlinx.kover.api.KoverTaskExtension
import org.gradle.api.JavaVersion.VERSION_1_8
import org.gradle.api.Project
import org.gradle.api.JavaVersion.VERSION_11
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED
import org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_ERROR
import org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_OUT
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.withType
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

plugins {
application
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.arrow.kotlin)
alias(libs.plugins.kotlin)
alias(libs.plugins.spotless)
alias(libs.plugins.kotest.multiplatform)
alias(libs.plugins.detekt)
alias(libs.plugins.dokka)
Expand All @@ -32,24 +31,28 @@ repositories {
mavenCentral()
}

group = property("projects.group").toString()
spotless {
kotlin {
ktfmt().googleStyle()
}
}

java {
sourceCompatibility = VERSION_1_8
targetCompatibility = VERSION_1_8
sourceCompatibility = VERSION_11
targetCompatibility = VERSION_11
}

tasks {
withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "1.8"
this.compilerOptions.jvmTarget.set(JvmTarget.JVM_11)
}

withType<Test>().configureEach {
maxParallelForks = Runtime.getRuntime().availableProcessors()
useJUnitPlatform()
testLogging {
exceptionFormat = TestExceptionFormat.FULL
events = setOf(PASSED, SKIPPED, FAILED, STANDARD_OUT, STANDARD_ERROR)
events = setOf(SKIPPED, FAILED, STANDARD_OUT, STANDARD_ERROR)
}
}

Expand All @@ -59,10 +62,36 @@ tasks {
}

kotlin {
explicitApi()

jvm()
js(IR) {
browser()
nodejs()
}

@OptIn(ExperimentalWasmDsl::class)
wasmJs()
linuxX64()
macosX64()
macosArm64()
iosSimulatorArm64()
iosX64()
linuxArm64()
watchosSimulatorArm64()
watchosX64()
watchosArm32()
watchosArm64()
tvosSimulatorArm64()
tvosX64()
tvosArm64()
iosArm64()
mingwX64()

sourceSets {
commonMain {
dependencies {
implementation(kotlin("stdlib-common"))
implementation(kotlin("stdlib"))
api(libs.arrow.optics)
api(libs.kotlinx.serialization.json)
}
Expand Down Expand Up @@ -118,12 +147,6 @@ tasks {

getByName("knitPrepare").dependsOn(getTasksByName("dokka", true))

register<Delete>("cleanDocs") {
val folder = file("docs").also { it.mkdir() }
val docsContent = folder.listFiles().filter { it != folder }
delete(docsContent)
}

withType<Detekt>().configureEach {
reports {
html.required.set(true)
Expand Down
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
kotlin.code.style=official
projects.group=io.github.nomisrev
kotlin.mpp.stability.nowarn=true

GROUP=io.github.nomisrev
SONATYPE_HOST=S01
RELEASE_SIGNING_ENABLED=true

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
28 changes: 11 additions & 17 deletions libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
[versions]
arrow = "1.2.1"
arrowGradle = "0.12.0-rc.24"
coroutines = "1.8.0"
dokka = "1.9.10"
kotlin = "1.9.22"
kotest = "5.8.0"
kotest-plugin = "5.8.0"
kover = "0.7.6"
arrow = "2.0.0-alpha.1"
dokka = "1.9.20"
kotlin = "2.0.0-RC3"
kotest = "5.9.0"
kover = "0.8.0"
detekt = "1.23.5"
kotest-arrow="1.4.0"
kotlinx-json="1.6.3"
kotlinx-knit="0.5.0"
publish="0.27.0"
publish="0.28.0"
knit="0.5.0"
spotless="6.25.0"

[libraries]
arrow-core = { module = "io.arrow-kt:arrow-core", version.ref = "arrow" }
arrow-optics = { module = "io.arrow-kt:arrow-optics", version.ref = "arrow" }
arrow-fx = { module = "io.arrow-kt:arrow-fx-coroutines", version.ref = "arrow" }
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
dokka-core = { module = "org.jetbrains.dokka:dokka-core", version.ref = "dokka" }
kotest-assertionsCore = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
kotest-frameworkEngine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" }
Expand All @@ -32,13 +26,13 @@ kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serializa
kotlinx-knit-test = { module = "org.jetbrains.kotlinx:kotlinx-knit-test", version.ref = "kotlinx-knit" }

[plugins]
arrow-formatter = { id = "io.arrow-kt.arrow-gradle-config-formatter", version.ref = "arrowGradle" }
arrow-kotlin = { id = "io.arrow-kt.arrow-gradle-config-kotlin", version.ref = "arrowGradle" }
kotlin = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" }
kotest-multiplatform = { id = "io.kotest.multiplatform", version.ref = "kotest-plugin" }
kotest-multiplatform = { id = "io.kotest.multiplatform", version.ref = "kotest" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
publish = { id = "com.vanniktech.maven.publish", version.ref="publish" }
knit = { id = "org.jetbrains.kotlinx.knit", version.ref="knit" }
knit = { id = "org.jetbrains.kotlinx.knit", version.ref="knit" }
spotless = { id = "com.diffplug.spotless", version.ref ="spotless" }
21 changes: 10 additions & 11 deletions src/commonMain/kotlin/io/github/nomisrev/JsonPath.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ package io.github.nomisrev
import arrow.core.Option
import arrow.core.None
import arrow.core.Some
import arrow.optics.Every
import arrow.optics.Optional
import arrow.optics.Traversal
import arrow.optics.typeclasses.At
import arrow.optics.typeclasses.Index
import arrow.optics.typeclasses.FilterIndex
Expand All @@ -21,7 +21,6 @@ import kotlinx.serialization.serializer
* Starting point of the JsonPath DSL
* This represents the _root_ of the path you want to define in your `JsonElement`
*/
@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE")
public object JsonPath : Optional<JsonElement, JsonElement> by Optional.id()

/** Extract a [Boolean] value from a [JsonElement] */
Expand Down Expand Up @@ -63,8 +62,8 @@ public inline val Optional<JsonElement, JsonElement>.`null`: Optional<JsonElemen
inline get() = this composeOptional Optional.jsonNull()

/** Select _every_ entry in [JsonArray] and [JsonObject] */
public inline val Optional<JsonElement, JsonElement>.every: Every<JsonElement, JsonElement>
inline get() = this compose Every.jsonElement()
public inline val Optional<JsonElement, JsonElement>.every: Traversal<JsonElement, JsonElement>
inline get() = this compose Traversal.jsonElement()

/**
* Select value at [selector]. The following syntax is supported for [selector]:
Expand Down Expand Up @@ -96,14 +95,14 @@ public fun Optional<JsonElement, JsonElement>.select(
*/
public fun Optional<JsonElement, JsonElement>.selectEvery(
selector: String
): Every<JsonElement, JsonElement> {
): Traversal<JsonElement, JsonElement> {
val inBrackets = matchNameInBrackets(selector)
val ixs = matchIndicesInBrackets(selector)
val startIx = matchStartIndex(selector)
val startEndIx = matchStartEndIndex(selector)
return when {
inBrackets != null -> get(inBrackets)
selector == "*" -> this compose Every.jsonElement() // inline definition of [every]
selector == "*" -> this compose Traversal.jsonElement() // inline definition of [every]
ixs != null -> filterIndex { it in ixs }
startIx != null -> filterIndex { it >= startIx }
startEndIx != null -> get(startEndIx.first until startEndIx.second)
Expand Down Expand Up @@ -136,9 +135,9 @@ public fun Optional<JsonElement, JsonElement>.pathEvery(
path: String,
fieldDelimiter: String = ".",
indexDelimiter: String = "["
): Every<JsonElement, JsonElement> =
): Traversal<JsonElement, JsonElement> =
path.splitTwice(fieldDelimiter, indexDelimiter).fold(this) {
acc: Every<JsonElement, JsonElement>, pathSelector -> acc.selectEvery(pathSelector)
acc: Traversal<JsonElement, JsonElement>, pathSelector -> acc.selectEvery(pathSelector)
}

/**
Expand All @@ -154,7 +153,7 @@ public fun Optional<JsonElement, JsonElement>.at(
/** Select keys out of an [JsonObject] with the given [predicate] */
public fun Optional<JsonElement, JsonElement>.filterKeys(
predicate: (keys: String) -> Boolean
): Every<JsonElement, JsonElement> =
): Traversal<JsonElement, JsonElement> =
`object` compose FilterIndex.map<String, JsonElement>().filter(predicate)

/** Select a [property] out of a [JsonObject] */
Expand All @@ -172,13 +171,13 @@ public operator fun Optional<JsonElement, JsonElement>.get(
/** Select all indices from the [range] out of a [JsonArray] */
public operator fun Optional<JsonElement, JsonElement>.get(
range: ClosedRange<Int>
): Every<JsonElement, JsonElement> =
): Traversal<JsonElement, JsonElement> =
filterIndex { it in range }

/** Select an indices out of a [JsonArray] with the given [predicate] */
public fun Optional<JsonElement, JsonElement>.filterIndex(
predicate: (index: Int) -> Boolean
): Every<JsonElement, JsonElement> =
): Traversal<JsonElement, JsonElement> =
array compose FilterIndex.list<JsonElement>().filter(predicate)

/** Extract a value of type [A] with an _implicit_ KotlinX Serializer */
Expand Down
Loading
Loading