Skip to content

Commit 9d31259

Browse files
authored
Update to Kotlin RC3, and Arrow 2 Alpha 1 (#68)
1 parent 51aeeba commit 9d31259

File tree

17 files changed

+164
-140
lines changed

17 files changed

+164
-140
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ on:
88
branches:
99
- main
1010

11-
env:
12-
JAVA_OPTS: -Xms512m -Xmx1024m
13-
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.configureondemand=true -Dorg.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8"
14-
1511
jobs:
1612
check:
1713
runs-on: ubuntu-latest

.github/workflows/githubpages.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ on:
44
release:
55
types: [published]
66

7-
env:
8-
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"
9-
107
jobs:
118
githubpages:
129
runs-on: ubuntu-latest

.github/workflows/publish.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ on:
1010
type: string
1111

1212
env:
13-
JAVA_OPTS: -Xms1g -Xmx3g
14-
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.configureondemand=true -Dorg.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8"
1513
ORG_GRADLE_PROJECT_mavenCentralUsername: '${{ secrets.SONATYPE_USER }}'
1614
ORG_GRADLE_PROJECT_mavenCentralPassword: '${{ secrets.SONATYPE_PWD }}'
1715
ORG_GRADLE_PROJECT_signingInMemoryKeyId: '${{ secrets.SIGNING_KEY_ID }}'

.github/workflows/pull_request.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: "Pull Request"
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 0
13+
14+
- name: Set up Java
15+
uses: actions/setup-java@v3
16+
with:
17+
distribution: 'zulu'
18+
java-version: 11
19+
20+
- name: Build
21+
uses: gradle/gradle-build-action@v2
22+
with:
23+
arguments: build

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,5 @@ kotlin-js-store
170170

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

173-
gradle-build-scan.txt
173+
gradle-build-scan.txt
174+
.kotlin

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ In the example below we select the _employees_ `JsonArray`,
101101
and then we select _every_ `JsonElement` in the `JsonArray`.
102102
We then _select_ the _name_ out of _every_ `JsonElement`.
103103

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

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

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

143143
You can then, apply a function to it using _modify_ like before.
@@ -151,13 +151,13 @@ fun main(): Unit {
151151
-->
152152
```kotlin
153153
val json: JsonElement = Json.decodeFromString(JSON_STRING)
154-
val employeesName: Every<JsonElement, String> = JsonPath.pathEvery("employees.*.name").string
154+
val employeesName: Traversal<JsonElement, String> = JsonPath.pathEvery("employees.*.name").string
155155
val res: JsonElement = employeesName.modify(json, String::uppercase).also(::println)
156156
employeesName.getAll(res).also(::println)
157157
```
158-
> You can get the full code [here](src/jvmTest/kotlin/example/example-readme-03.kt).
158+
> You can get the full code [here](src/jvmTest/kotlin/example/example-readme-04.kt).
159159
160160
```text
161161
{"name":"Arrow","address":{"city":"Functional Town","street":{"number":1337,"name":"Functional street"}},"employees":[{"name":"JOHN","lastName":"doe"},{"name":"JANE","lastName":"doe"}]}
162162
[JOHN, JANE]
163-
```
163+
```

build.gradle.kts

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@ import kotlinx.knit.KnitPluginExtension
22
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
33
import io.gitlab.arturbosch.detekt.Detekt
44
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
5-
import kotlinx.kover.api.KoverTaskExtension
6-
import org.gradle.api.JavaVersion.VERSION_1_8
7-
import org.gradle.api.Project
5+
import org.gradle.api.JavaVersion.VERSION_11
86
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
97
import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
10-
import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
118
import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED
129
import org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_ERROR
1310
import org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_OUT
1411
import org.gradle.kotlin.dsl.configure
1512
import org.gradle.kotlin.dsl.withType
1613
import org.jetbrains.dokka.gradle.DokkaTask
14+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
15+
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
1716

1817
plugins {
1918
application
20-
alias(libs.plugins.kotlin.multiplatform)
21-
alias(libs.plugins.arrow.kotlin)
19+
alias(libs.plugins.kotlin)
20+
alias(libs.plugins.spotless)
2221
alias(libs.plugins.kotest.multiplatform)
2322
alias(libs.plugins.detekt)
2423
alias(libs.plugins.dokka)
@@ -32,24 +31,28 @@ repositories {
3231
mavenCentral()
3332
}
3433

35-
group = property("projects.group").toString()
34+
spotless {
35+
kotlin {
36+
ktfmt().googleStyle()
37+
}
38+
}
3639

3740
java {
38-
sourceCompatibility = VERSION_1_8
39-
targetCompatibility = VERSION_1_8
41+
sourceCompatibility = VERSION_11
42+
targetCompatibility = VERSION_11
4043
}
4144

4245
tasks {
4346
withType<KotlinCompile>().configureEach {
44-
kotlinOptions.jvmTarget = "1.8"
47+
this.compilerOptions.jvmTarget.set(JvmTarget.JVM_11)
4548
}
4649

4750
withType<Test>().configureEach {
4851
maxParallelForks = Runtime.getRuntime().availableProcessors()
4952
useJUnitPlatform()
5053
testLogging {
5154
exceptionFormat = TestExceptionFormat.FULL
52-
events = setOf(PASSED, SKIPPED, FAILED, STANDARD_OUT, STANDARD_ERROR)
55+
events = setOf(SKIPPED, FAILED, STANDARD_OUT, STANDARD_ERROR)
5356
}
5457
}
5558

@@ -59,10 +62,36 @@ tasks {
5962
}
6063

6164
kotlin {
65+
explicitApi()
66+
67+
jvm()
68+
js(IR) {
69+
browser()
70+
nodejs()
71+
}
72+
73+
@OptIn(ExperimentalWasmDsl::class)
74+
wasmJs()
75+
linuxX64()
76+
macosX64()
77+
macosArm64()
78+
iosSimulatorArm64()
79+
iosX64()
80+
linuxArm64()
81+
watchosSimulatorArm64()
82+
watchosX64()
83+
watchosArm32()
84+
watchosArm64()
85+
tvosSimulatorArm64()
86+
tvosX64()
87+
tvosArm64()
88+
iosArm64()
89+
mingwX64()
90+
6291
sourceSets {
6392
commonMain {
6493
dependencies {
65-
implementation(kotlin("stdlib-common"))
94+
implementation(kotlin("stdlib"))
6695
api(libs.arrow.optics)
6796
api(libs.kotlinx.serialization.json)
6897
}
@@ -118,12 +147,6 @@ tasks {
118147

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

121-
register<Delete>("cleanDocs") {
122-
val folder = file("docs").also { it.mkdir() }
123-
val docsContent = folder.listFiles().filter { it != folder }
124-
delete(docsContent)
125-
}
126-
127150
withType<Detekt>().configureEach {
128151
reports {
129152
html.required.set(true)

gradle.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
kotlin.code.style=official
2-
projects.group=io.github.nomisrev
3-
kotlin.mpp.stability.nowarn=true
42

3+
GROUP=io.github.nomisrev
54
SONATYPE_HOST=S01
65
RELEASE_SIGNING_ENABLED=true
76

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

libs.versions.toml

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
[versions]
2-
arrow = "1.2.1"
3-
arrowGradle = "0.12.0-rc.24"
4-
coroutines = "1.8.0"
5-
dokka = "1.9.10"
6-
kotlin = "1.9.22"
7-
kotest = "5.8.0"
8-
kotest-plugin = "5.8.0"
9-
kover = "0.7.6"
2+
arrow = "2.0.0-alpha.1"
3+
dokka = "1.9.20"
4+
kotlin = "2.0.0-RC3"
5+
kotest = "5.9.0"
6+
kover = "0.8.0"
107
detekt = "1.23.5"
118
kotest-arrow="1.4.0"
129
kotlinx-json="1.6.3"
1310
kotlinx-knit="0.5.0"
14-
publish="0.27.0"
11+
publish="0.28.0"
1512
knit="0.5.0"
13+
spotless="6.25.0"
1614

1715
[libraries]
18-
arrow-core = { module = "io.arrow-kt:arrow-core", version.ref = "arrow" }
1916
arrow-optics = { module = "io.arrow-kt:arrow-optics", version.ref = "arrow" }
20-
arrow-fx = { module = "io.arrow-kt:arrow-fx-coroutines", version.ref = "arrow" }
21-
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
22-
coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
2317
dokka-core = { module = "org.jetbrains.dokka:dokka-core", version.ref = "dokka" }
2418
kotest-assertionsCore = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
2519
kotest-frameworkEngine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" }
@@ -32,13 +26,13 @@ kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serializa
3226
kotlinx-knit-test = { module = "org.jetbrains.kotlinx:kotlinx-knit-test", version.ref = "kotlinx-knit" }
3327

3428
[plugins]
35-
arrow-formatter = { id = "io.arrow-kt.arrow-gradle-config-formatter", version.ref = "arrowGradle" }
36-
arrow-kotlin = { id = "io.arrow-kt.arrow-gradle-config-kotlin", version.ref = "arrowGradle" }
29+
kotlin = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
3730
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
3831
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" }
39-
kotest-multiplatform = { id = "io.kotest.multiplatform", version.ref = "kotest-plugin" }
32+
kotest-multiplatform = { id = "io.kotest.multiplatform", version.ref = "kotest" }
4033
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
4134
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
4235
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
4336
publish = { id = "com.vanniktech.maven.publish", version.ref="publish" }
44-
knit = { id = "org.jetbrains.kotlinx.knit", version.ref="knit" }
37+
knit = { id = "org.jetbrains.kotlinx.knit", version.ref="knit" }
38+
spotless = { id = "com.diffplug.spotless", version.ref ="spotless" }

src/commonMain/kotlin/io/github/nomisrev/JsonPath.kt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ package io.github.nomisrev
44
import arrow.core.Option
55
import arrow.core.None
66
import arrow.core.Some
7-
import arrow.optics.Every
87
import arrow.optics.Optional
8+
import arrow.optics.Traversal
99
import arrow.optics.typeclasses.At
1010
import arrow.optics.typeclasses.Index
1111
import arrow.optics.typeclasses.FilterIndex
@@ -21,7 +21,6 @@ import kotlinx.serialization.serializer
2121
* Starting point of the JsonPath DSL
2222
* This represents the _root_ of the path you want to define in your `JsonElement`
2323
*/
24-
@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE")
2524
public object JsonPath : Optional<JsonElement, JsonElement> by Optional.id()
2625

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

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

6968
/**
7069
* Select value at [selector]. The following syntax is supported for [selector]:
@@ -96,14 +95,14 @@ public fun Optional<JsonElement, JsonElement>.select(
9695
*/
9796
public fun Optional<JsonElement, JsonElement>.selectEvery(
9897
selector: String
99-
): Every<JsonElement, JsonElement> {
98+
): Traversal<JsonElement, JsonElement> {
10099
val inBrackets = matchNameInBrackets(selector)
101100
val ixs = matchIndicesInBrackets(selector)
102101
val startIx = matchStartIndex(selector)
103102
val startEndIx = matchStartEndIndex(selector)
104103
return when {
105104
inBrackets != null -> get(inBrackets)
106-
selector == "*" -> this compose Every.jsonElement() // inline definition of [every]
105+
selector == "*" -> this compose Traversal.jsonElement() // inline definition of [every]
107106
ixs != null -> filterIndex { it in ixs }
108107
startIx != null -> filterIndex { it >= startIx }
109108
startEndIx != null -> get(startEndIx.first until startEndIx.second)
@@ -136,9 +135,9 @@ public fun Optional<JsonElement, JsonElement>.pathEvery(
136135
path: String,
137136
fieldDelimiter: String = ".",
138137
indexDelimiter: String = "["
139-
): Every<JsonElement, JsonElement> =
138+
): Traversal<JsonElement, JsonElement> =
140139
path.splitTwice(fieldDelimiter, indexDelimiter).fold(this) {
141-
acc: Every<JsonElement, JsonElement>, pathSelector -> acc.selectEvery(pathSelector)
140+
acc: Traversal<JsonElement, JsonElement>, pathSelector -> acc.selectEvery(pathSelector)
142141
}
143142

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

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

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

184183
/** Extract a value of type [A] with an _implicit_ KotlinX Serializer */

0 commit comments

Comments
 (0)