diff --git a/arrow-libs/core/arrow-annotations/src/commonMain/kotlin/arrow/optics/optics.kt b/arrow-libs/core/arrow-annotations/src/commonMain/kotlin/arrow/optics/optics.kt index f188d79847e..21d45da1517 100644 --- a/arrow-libs/core/arrow-annotations/src/commonMain/kotlin/arrow/optics/optics.kt +++ b/arrow-libs/core/arrow-annotations/src/commonMain/kotlin/arrow/optics/optics.kt @@ -8,7 +8,7 @@ import kotlin.annotation.AnnotationTarget.CLASS /** * Empty arrays means "Everything that matches annotated class" */ -public annotation class optics(val targets: Array = emptyArray()) +public annotation class optics(val targets: Array = []) public enum class OpticsTarget { ISO, LENS, PRISM, OPTIONAL, DSL diff --git a/arrow-libs/core/arrow-atomic/src/commonTest/kotlin/arrow/atomic/AtomicTest.kt b/arrow-libs/core/arrow-atomic/src/commonTest/kotlin/arrow/atomic/AtomicTest.kt index 778dd19d344..5a888dc7fb8 100644 --- a/arrow-libs/core/arrow-atomic/src/commonTest/kotlin/arrow/atomic/AtomicTest.kt +++ b/arrow-libs/core/arrow-atomic/src/commonTest/kotlin/arrow/atomic/AtomicTest.kt @@ -74,10 +74,10 @@ class AtomicTest { fun tryUpdateShouldFailToUpdateIfModificationHasOccurred() = runTest { checkAll(Arb.string()) { x -> val ref = Atomic(x) - ref.tryUpdate { + ref.tryUpdate { x2 -> suspend { ref.update { it + "a" } } .startCoroutineUninterceptedOrReturn(Continuation(EmptyCoroutineContext) { }) - it + "b" + x2 + "b" } shouldBe false } } diff --git a/arrow-libs/core/arrow-autoclose/src/commonTest/kotlin/arrow/AutoCloseTest.kt b/arrow-libs/core/arrow-autoclose/src/commonTest/kotlin/arrow/AutoCloseTest.kt index 0fa3dc025c6..482a027b22e 100644 --- a/arrow-libs/core/arrow-autoclose/src/commonTest/kotlin/arrow/AutoCloseTest.kt +++ b/arrow-libs/core/arrow-autoclose/src/commonTest/kotlin/arrow/AutoCloseTest.kt @@ -9,6 +9,9 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.toList import kotlinx.coroutines.test.runTest +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.InvocationKind +import kotlin.contracts.contract import kotlin.coroutines.cancellation.CancellationException import kotlin.test.Test @@ -215,7 +218,11 @@ class AutoCloseTest { } // copied from Kotest so we can inline it +@OptIn(ExperimentalContracts::class) inline fun shouldThrow(block: () -> Any?): T { + contract { + callsInPlace(block, InvocationKind.AT_MOST_ONCE) + } assertionCounter.inc() val expectedExceptionClass = T::class val thrownThrowable = try { diff --git a/arrow-libs/core/arrow-core/src/androidAndJvmMain/kotlin/arrow/core/raise/CancellationExceptionNoTrace.kt b/arrow-libs/core/arrow-core/src/androidAndJvmMain/kotlin/arrow/core/raise/CancellationExceptionNoTrace.kt index 40215c964e1..6b2b868ad5c 100644 --- a/arrow-libs/core/arrow-core/src/androidAndJvmMain/kotlin/arrow/core/raise/CancellationExceptionNoTrace.kt +++ b/arrow-libs/core/arrow-core/src/androidAndJvmMain/kotlin/arrow/core/raise/CancellationExceptionNoTrace.kt @@ -1,7 +1,5 @@ package arrow.core.raise -import kotlin.coroutines.cancellation.CancellationException - /* * Inspired by KotlinX Coroutines: * https://github.com/Kotlin/kotlinx.coroutines/blob/3788889ddfd2bcfedbff1bbca10ee56039e024a2/kotlinx-coroutines-core/jvm/src/Exceptions.kt#L29 diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Comparison.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Comparison.kt index c80a35bfc36..201e038cf65 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Comparison.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Comparison.kt @@ -5,9 +5,9 @@ public fun > sort(a: A, b: A): Pair = public fun > sort(a: A, b: A, c: A): Triple = when { - a <= b && b <= c -> Triple(a, b, c) + b in a..c -> Triple(a, b, c) a <= b -> if (c <= a) Triple(c, a, b) else Triple(a, c, b) - b <= a && a <= c -> Triple(b, a, c) + a in b..c -> Triple(b, a, c) else -> if (c <= b) Triple(c, b, a) else Triple(b, c, a) } @@ -33,9 +33,9 @@ public fun sort(a: Byte, b: Byte): Pair = public fun sort(a: Byte, b: Byte, c: Byte): Triple = when { - a <= b && b <= c -> Triple(a, b, c) + b in a..c -> Triple(a, b, c) a <= b -> if (c <= a) Triple(c, a, b) else Triple(a, c, b) - b <= a && a <= c -> Triple(b, a, c) + a in b..c -> Triple(b, a, c) else -> if (c <= b) Triple(c, b, a) else Triple(b, c, a) } @@ -47,9 +47,9 @@ public fun sort(a: Short, b: Short): Pair = public fun sort(a: Short, b: Short, c: Short): Triple = when { - a <= b && b <= c -> Triple(a, b, c) + b in a..c -> Triple(a, b, c) a <= b -> if (c <= a) Triple(c, a, b) else Triple(a, c, b) - b <= a && a <= c -> Triple(b, a, c) + a in b..c -> Triple(b, a, c) else -> if (c <= b) Triple(c, b, a) else Triple(b, c, a) } @@ -61,9 +61,9 @@ public fun sort(a: Int, b: Int): Pair = public fun sort(a: Int, b: Int, c: Int): Triple = when { - a <= b && b <= c -> Triple(a, b, c) + b in a..c -> Triple(a, b, c) a <= b -> if (c <= a) Triple(c, a, b) else Triple(a, c, b) - b <= a && a <= c -> Triple(b, a, c) + a in b..c -> Triple(b, a, c) else -> if (c <= b) Triple(c, b, a) else Triple(b, c, a) } @@ -75,9 +75,9 @@ public fun sort(a: Long, b: Long): Pair = public fun sort(a: Long, b: Long, c: Long): Triple = when { - a <= b && b <= c -> Triple(a, b, c) + b in a..c -> Triple(a, b, c) a <= b -> if (c <= a) Triple(c, a, b) else Triple(a, c, b) - b <= a && a <= c -> Triple(b, a, c) + a in b..c -> Triple(b, a, c) else -> if (c <= b) Triple(c, b, a) else Triple(b, c, a) } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt index 0fe62668640..a446c7ade8c 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt @@ -777,7 +777,7 @@ public sealed class Either { /** * The left side of the disjoint union, as opposed to the [Right] side. */ - public data class Left constructor(val value: A) : Either() { + public data class Left(val value: A) : Either() { override fun toString(): String = "Either.Left($value)" public companion object @@ -786,7 +786,7 @@ public sealed class Either { /** * The right side of the disjoint union, as opposed to the [Left] side. */ - public data class Right constructor(val value: B) : Either() { + public data class Right(val value: B) : Either() { override fun toString(): String = "Either.Right($value)" public companion object { diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt index 788030e6414..78db21db8da 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt @@ -51,10 +51,10 @@ public sealed class Ior { */ public fun isLeft(): Boolean { contract { - returns(true) implies (this@Ior is Ior.Left) - returns(false) implies (this@Ior is Ior.Right || this@Ior is Ior.Both) + returns(true) implies (this@Ior is Left) + returns(false) implies (this@Ior is Right || this@Ior is Both) } - return this@Ior is Ior.Left + return this@Ior is Left } /** @@ -75,10 +75,10 @@ public sealed class Ior { */ public fun isRight(): Boolean { contract { - returns(true) implies (this@Ior is Ior.Right) - returns(false) implies (this@Ior is Ior.Left || this@Ior is Ior.Both) + returns(true) implies (this@Ior is Right) + returns(false) implies (this@Ior is Left || this@Ior is Both) } - return this@Ior is Ior.Right + return this@Ior is Right } /** @@ -98,10 +98,10 @@ public sealed class Ior { */ public fun isBoth(): Boolean { contract { - returns(false) implies (this@Ior is Ior.Right || this@Ior is Ior.Left) - returns(true) implies (this@Ior is Ior.Both) + returns(false) implies (this@Ior is Right || this@Ior is Left) + returns(true) implies (this@Ior is Both) } - return this@Ior is Ior.Both + return this@Ior is Both } public companion object { @@ -451,11 +451,11 @@ public inline fun Ior.getOrElse(default: (A) -> B): B { } -public fun Pair.bothIor(): Ior = Ior.Both(this.first, this.second) +public fun Pair.bothIor(): Ior = Both(this.first, this.second) -public fun A.leftIor(): Ior = Ior.Left(this) +public fun A.leftIor(): Ior = Left(this) -public fun A.rightIor(): Ior = Ior.Right(this) +public fun A.rightIor(): Ior = Right(this) public inline fun Ior.combine(other: Ior, combineA: (A, A) -> A, combineB: (B, B) -> B): Ior { contract { @@ -463,22 +463,22 @@ public inline fun Ior.combine(other: Ior, combineA: (A, A) -> callsInPlace(combineB, InvocationKind.AT_MOST_ONCE) } return when (this) { - is Ior.Left -> when (other) { - is Ior.Left -> Ior.Left(combineA(value, other.value)) - is Ior.Right -> Ior.Both(value, other.value) - is Ior.Both -> Ior.Both(combineA(value, other.leftValue), other.rightValue) + is Left -> when (other) { + is Left -> Left(combineA(value, other.value)) + is Right -> Both(value, other.value) + is Both -> Both(combineA(value, other.leftValue), other.rightValue) } - is Ior.Right -> when (other) { - is Ior.Left -> Ior.Both(other.value, value) - is Ior.Right -> Ior.Right(combineB(value, other.value)) - is Ior.Both -> Ior.Both(other.leftValue, combineB(value, other.rightValue)) + is Right -> when (other) { + is Left -> Both(other.value, value) + is Right -> Right(combineB(value, other.value)) + is Both -> Both(other.leftValue, combineB(value, other.rightValue)) } - is Ior.Both -> when (other) { - is Ior.Left -> Ior.Both(combineA(leftValue, other.value), rightValue) - is Ior.Right -> Ior.Both(leftValue, combineB(rightValue, other.value)) - is Ior.Both -> Ior.Both(combineA(leftValue, other.leftValue), combineB(rightValue, other.rightValue)) + is Both -> when (other) { + is Left -> Both(combineA(leftValue, other.value), rightValue) + is Right -> Both(leftValue, combineB(rightValue, other.value)) + is Both -> Both(combineA(leftValue, other.leftValue), combineB(rightValue, other.rightValue)) } } } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptySet.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptySet.kt index 327fb562cb8..5c6c7441734 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptySet.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptySet.kt @@ -5,7 +5,6 @@ package arrow.core import arrow.core.raise.RaiseAccumulate import kotlin.experimental.ExperimentalTypeInference import kotlin.jvm.JvmInline -import kotlin.jvm.JvmName @JvmInline public value class NonEmptySet internal constructor( diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/TupleN.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/TupleN.kt index 1fbff275366..1bb10afcfe4 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/TupleN.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/TupleN.kt @@ -13,12 +13,3 @@ public operator fun Tuple5.plus(f: F): Tuple6< public operator fun Tuple6.plus(g: G): Tuple7 = Tuple7(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, g) public operator fun Tuple7.plus(h: H): Tuple8 = Tuple8(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, h) public operator fun Tuple8.plus(i: I): Tuple9 = Tuple9(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, this.eighth, i) - -private const val INT_MAX_POWER_OF_TWO: Int = Int.MAX_VALUE / 2 + 1 - -internal fun mapCapacity(expectedSize: Int): Int = - when { - expectedSize < 3 -> expectedSize + 1 - expectedSize < INT_MAX_POWER_OF_TWO -> expectedSize + expectedSize / 3 - else -> Int.MAX_VALUE - } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt index 6cd1478a472..70ff46da237 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt @@ -3,7 +3,6 @@ package arrow.core import arrow.core.raise.either -import arrow.core.raise.mapOrAccumulate import arrow.core.raise.RaiseAccumulate import arrow.core.raise.mapValuesOrAccumulate import kotlin.experimental.ExperimentalTypeInference diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt index 4fb8e0956bc..14948487a86 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt @@ -244,9 +244,9 @@ class EitherTest { val all = listOf(a, b, c, d, e, f, g, h, i) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>().fold("") { acc, t -> "$acc${t.value}" }.left() + all.filterLefts().fold("") { acc, t -> "$acc$t" }.left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple9(it[0], it[1], it[2], it[3], it[4], it[5], it[6], it[7], it[8]).right() } } @@ -272,12 +272,12 @@ class EitherTest { val all = listOf(a, b, c, d, e, f, g, h, i) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>().map { it.value } + all.filterLefts() .toNonEmptyListOrNull() .shouldNotBeNull() .left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple9(it[0], it[1], it[2], it[3], it[4], it[5], it[6], it[7], it[8]).right() } } @@ -303,13 +303,13 @@ class EitherTest { val all = listOf(a, b, c, d, e, f, g, h, i) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>>() - .flatMap { it.value } + all.filterLefts() + .flatten() .toNonEmptyListOrNull() .shouldNotBeNull() .left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple9(it[0], it[1], it[2], it[3], it[4], it[5], it[6], it[7], it[8]).right() } } @@ -328,9 +328,9 @@ class EitherTest { val all = listOf(a, b) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>().fold("") { acc, t -> "$acc${t.value}" }.left() + all.filterLefts().fold("") { acc, t -> "$acc$t" }.left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Pair(it[0], it[1]).right() } } @@ -350,9 +350,9 @@ class EitherTest { val all = listOf(a, b, c) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>().fold("") { acc, t -> "$acc${t.value}" }.left() + all.filterLefts().fold("") { acc, t -> "$acc$t" }.left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Triple(it[0], it[1], it[2]).right() } } @@ -373,9 +373,9 @@ class EitherTest { val all = listOf(a, b, c, d) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>().fold("") { acc, t -> "$acc${t.value}" }.left() + all.filterLefts().fold("") { acc, t -> "$acc$t" }.left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple4(it[0], it[1], it[2], it[3]).right() } } @@ -397,9 +397,9 @@ class EitherTest { val all = listOf(a, b, c, d, e) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>().fold("") { acc, t -> "$acc${t.value}" }.left() + all.filterLefts().fold("") { acc, t -> "$acc$t" }.left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple5(it[0], it[1], it[2], it[3], it[4]).right() } } @@ -422,9 +422,9 @@ class EitherTest { val all = listOf(a, b, c, d, e, f) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>().fold("") { acc, t -> "$acc${t.value}" }.left() + all.filterLefts().fold("") { acc, t -> "$acc$t" }.left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple6(it[0], it[1], it[2], it[3], it[4], it[5]).right() } } @@ -448,9 +448,9 @@ class EitherTest { val all = listOf(a, b, c, d, e, f, g) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>().fold("") { acc, t -> "$acc${t.value}" }.left() + all.filterLefts().fold("") { acc, t -> "$acc$t" }.left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple7(it[0], it[1], it[2], it[3], it[4], it[5], it[6]).right() } } @@ -475,9 +475,9 @@ class EitherTest { val all = listOf(a, b, c, d, e, f, g, h) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>().fold("") { acc, t -> "$acc${t.value}" }.left() + all.filterLefts().fold("") { acc, t -> "$acc$t" }.left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple8(it[0], it[1], it[2], it[3], it[4], it[5], it[6], it[7]).right() } } @@ -496,12 +496,12 @@ class EitherTest { val all = listOf(a, b) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>().map { it.value } + all.filterLefts() .toNonEmptyListOrNull() .shouldNotBeNull() .left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Pair(it[0], it[1]).right() } } @@ -521,12 +521,12 @@ class EitherTest { val all = listOf(a, b, c) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>().map { it.value } + all.filterLefts() .toNonEmptyListOrNull() .shouldNotBeNull() .left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Triple(it[0], it[1], it[2]).right() } } @@ -547,12 +547,12 @@ class EitherTest { val all = listOf(a, b, c, d) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>().map { it.value } + all.filterLefts() .toNonEmptyListOrNull() .shouldNotBeNull() .left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple4(it[0], it[1], it[2], it[3]).right() } } @@ -574,12 +574,12 @@ class EitherTest { val all = listOf(a, b, c, d, e) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>().map { it.value } + all.filterLefts() .toNonEmptyListOrNull() .shouldNotBeNull() .left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple5(it[0], it[1], it[2], it[3], it[4]).right() } } @@ -602,12 +602,12 @@ class EitherTest { val all = listOf(a, b, c, d, e, f) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>().map { it.value } + all.filterLefts() .toNonEmptyListOrNull() .shouldNotBeNull() .left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple6(it[0], it[1], it[2], it[3], it[4], it[5]).right() } } @@ -631,12 +631,12 @@ class EitherTest { val all = listOf(a, b, c, d, e, f, g) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>().map { it.value } + all.filterLefts() .toNonEmptyListOrNull() .shouldNotBeNull() .left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple7(it[0], it[1], it[2], it[3], it[4], it[5], it[6]).right() } } @@ -661,12 +661,12 @@ class EitherTest { val all = listOf(a, b, c, d, e, f, g, h) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>().map { it.value } + all.filterLefts() .toNonEmptyListOrNull() .shouldNotBeNull() .left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple8(it[0], it[1], it[2], it[3], it[4], it[5], it[6], it[7]).right() } } @@ -685,13 +685,13 @@ class EitherTest { val all = listOf(a, b) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>>() - .flatMap { it.value } + all.filterLefts() + .flatten() .toNonEmptyListOrNull() .shouldNotBeNull() .left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Pair(it[0], it[1]).right() } } @@ -711,13 +711,13 @@ class EitherTest { val all = listOf(a, b, c) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>>() - .flatMap { it.value } + all.filterLefts() + .flatten() .toNonEmptyListOrNull() .shouldNotBeNull() .left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Triple(it[0], it[1], it[2]).right() } } @@ -738,13 +738,13 @@ class EitherTest { val all = listOf(a, b, c, d) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>>() - .flatMap { it.value } + all.filterLefts() + .flatten() .toNonEmptyListOrNull() .shouldNotBeNull() .left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple4(it[0], it[1], it[2], it[3]).right() } } @@ -766,13 +766,13 @@ class EitherTest { val all = listOf(a, b, c, d, e) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>>() - .flatMap { it.value } + all.filterLefts() + .flatten() .toNonEmptyListOrNull() .shouldNotBeNull() .left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple5(it[0], it[1], it[2], it[3], it[4]).right() } } @@ -795,13 +795,13 @@ class EitherTest { val all = listOf(a, b, c, d, e, f) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>>() - .flatMap { it.value } + all.filterLefts() + .flatten() .toNonEmptyListOrNull() .shouldNotBeNull() .left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple6(it[0], it[1], it[2], it[3], it[4], it[5]).right() } } @@ -825,13 +825,13 @@ class EitherTest { val all = listOf(a, b, c, d, e, f, g) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>>() - .flatMap { it.value } + all.filterLefts() + .flatten() .toNonEmptyListOrNull() .shouldNotBeNull() .left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple7(it[0], it[1], it[2], it[3], it[4], it[5], it[6]).right() } } @@ -856,13 +856,13 @@ class EitherTest { val all = listOf(a, b, c, d, e, f, g, h) val expected = if (all.any { it.isLeft() }) { - all.filterIsInstance>>() - .flatMap { it.value } + all.filterLefts() + .flatten() .toNonEmptyListOrNull() .shouldNotBeNull() .left() } else { - all.filterIsInstance>().map { it.value }.let { + all.filterRights().let { Tuple8(it[0], it[1], it[2], it[3], it[4], it[5], it[6], it[7]).right() } } @@ -924,9 +924,7 @@ class EitherTest { fun catchOrThrowRuntimeException() = runTest { checkAll(20, Arb.int(-2..2)) { a -> fun func() = 1001 / a - val res = Either.catchOrThrow(::func) - - when (res) { + when (val res = Either.catch(::func)) { is Left -> { res.value::class shouldBe ArithmeticException::class } @@ -960,7 +958,7 @@ class EitherTest { fun func(i: Int) = (i + 1).left() checkAll(Arb.either(Arb.int(), Arb.int())) { e -> - val expected = e.fold(::func, { e }) + val expected = e.fold(::func) { e } e.handleErrorWith(::func) shouldBe expected } } @@ -1028,3 +1026,9 @@ class EitherTest { } } } + +private fun List>.filterRights(): List = + filterIsInstance>().map { it.value } + +private fun List>.filterLefts(): List = + filterIsInstance>().map { it.value } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EffectSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EffectSpec.kt index 1ecd0f0464b..700d95d42f8 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EffectSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EffectSpec.kt @@ -45,7 +45,7 @@ class EffectSpec { effect { try { raise(s()) - } catch (e: RaiseCancellationException) { + } catch (_: RaiseCancellationException) { i() } }.getOrElse { unreachable() } shouldBe i() @@ -72,7 +72,7 @@ class EffectSpec { effect { try { raise(s()) - } catch (e: RaiseCancellationException) { + } catch (_: RaiseCancellationException) { i() } raise(s2()) @@ -111,7 +111,7 @@ class EffectSpec { } @Test fun recoverSuccess() = runTest { - checkAll(Arb.int().suspend(), Arb.long().suspend()) { i, l -> + checkAll(Arb.int().suspend()) { i -> effect { effect { i() } getOrElse { unreachable() } }.getOrElse { unreachable() } shouldBe i() @@ -173,7 +173,7 @@ class EffectSpec { } @Test fun recoverCatchRaiseAndThrow() = runTest { - checkAll(Arb.long().suspend(), Arb.string().suspend()) { l, s -> + checkAll(Arb.long().suspend()) { l -> effect { effect { raise(l()) @@ -199,7 +199,7 @@ class EffectSpec { } @Test fun recoverCatchSuccess() = runTest { - checkAll(Arb.int().suspend(), Arb.long().suspend()) { i, l -> + checkAll(Arb.int().suspend()) { i -> effect { effect { i() } .catch { unreachable() }.getOrElse { unreachable() } @@ -567,7 +567,7 @@ class EffectSpec { } @Test fun catchReifiedErrorPathAndNoMatch() = runTest { - checkAll(Arb.string().suspend(), Arb.int().suspend()) { msg, error -> + checkAll(Arb.string().suspend()) { msg -> effect { throw RuntimeException(msg()) }.catch { _: ArithmeticException -> @@ -664,7 +664,7 @@ class EffectSpec { val expected = eithers.mapNotNull { it.leftOrNull() }.toNonEmptyListOrNull()?.left() ?: eithers.mapNotNull { it.getOrNull() }.right() - either, List> { + either { zipOrAccumulate( { eithers.bindAll() }, { emptyList() } @@ -687,7 +687,7 @@ class EffectSpec { val expected = eithers.mapNotNull { it.leftOrNull() }.toNonEmptyListOrNull()?.left() ?: eithers.mapNotNull { it.getOrNull() }.right() - either, NonEmptyList> { + either { zipOrAccumulate( { eithers.bindAll() }, { emptyList() } @@ -710,7 +710,7 @@ class EffectSpec { val expected = eithers.mapNotNull { it.leftOrNull() }.toNonEmptyListOrNull()?.left() ?: eithers.mapNotNull { it.getOrNull() }.toSet().right() - either, NonEmptySet> { + either { zipOrAccumulate( { eithers.bindAll() }, { emptySet() } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/RaiseAccumulateSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/RaiseAccumulateSpec.kt index 0de771fb4f6..7cbecde2306 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/RaiseAccumulateSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/RaiseAccumulateSpec.kt @@ -1,7 +1,6 @@ @file:OptIn(ExperimentalRaiseAccumulateApi::class) package arrow.core.raise -import arrow.core.NonEmptyList import arrow.core.left import arrow.core.nonEmptyListOf import arrow.core.right @@ -11,7 +10,7 @@ import kotlinx.coroutines.test.runTest class RaiseAccumulateSpec { @Test fun raiseAccumulateTakesPrecedenceOverExtensionFunction() = runTest { - either, Int> { + either { zipOrAccumulate( { ensure(false) { "false" } }, { mapOrAccumulate(1..2) { ensure(false) { "$it: IsFalse" } } } @@ -21,8 +20,8 @@ class RaiseAccumulateSpec { @Test fun raiseAccumulateTakesPrecedenceOverExtensionFunctionNel() { accumulate(::either) { - val x by accumulating { ensure(false) { "false" } } - val y by accumulating { mapOrAccumulate(1..2) { ensure(false) { "$it: IsFalse" } } } + accumulating { ensure(false) { "false" } } + accumulating { mapOrAccumulate(1..2) { ensure(false) { "$it: IsFalse" } } } 1 } shouldBe nonEmptyListOf("false", "1: IsFalse", "2: IsFalse").left() } @@ -37,13 +36,11 @@ class RaiseAccumulateSpec { @Test fun raiseAccumulatingTwoFailures() { accumulate(::either) { - val x by accumulating { + val x: Int by accumulating { raise("hello") - 1 } - val y by accumulating { + val y: Int by accumulating { raise("bye") - 2 } x + y } shouldBe nonEmptyListOf("hello", "bye").left() @@ -52,7 +49,7 @@ class RaiseAccumulateSpec { @Test fun raiseAccumulatingOneFailure() { accumulate(::either) { val x by accumulating { 1 } - val y by accumulating { raise("bye") ; 2 } + val y: Int by accumulating { raise("bye") } x + y } shouldBe nonEmptyListOf("bye").left() } @@ -75,10 +72,8 @@ class RaiseAccumulateSpec { @Test fun raiseAccumulatingIntermediateRaise() { accumulate(::either) { - val x by accumulating { raise("hello") ; 1 } + accumulating { raise("hello") } raise("hi") - val y by accumulating { 2 } - x + y } shouldBe nonEmptyListOf("hello", "hi").left() } } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/predef.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/predef.kt index 07aac344e0b..856bd39e830 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/predef.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/predef.kt @@ -4,8 +4,4 @@ import arrow.core.identity suspend fun Effect.value(): A = fold(::identity, ::identity) -suspend fun Effect.runCont(): Any? = fold(::identity, ::identity) - fun EagerEffect.value(): A = fold(::identity, ::identity) - -fun EagerEffect.runCont(): Any? = fold(::identity, ::identity) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/GeneratorsTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/GeneratorsTest.kt index cad5d435bbe..1f14473caa6 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/GeneratorsTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/GeneratorsTest.kt @@ -8,7 +8,6 @@ import io.kotest.property.RandomSource import io.kotest.property.arbitrary.boolean import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.next -import io.kotest.property.arbitrary.orNull import io.kotest.property.checkAll import kotlin.test.Test import kotlinx.coroutines.test.runTest diff --git a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/NonFatalJvmTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/NonFatalJvmTest.kt index 73e650f97ad..4ce64e0ce24 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/NonFatalJvmTest.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/NonFatalJvmTest.kt @@ -1,6 +1,5 @@ package arrow.core -import arrow.core.shouldThrowAny import io.kotest.matchers.shouldBe import kotlinx.coroutines.test.runTest import kotlin.test.Test diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/arrow/core/raise/TraceJvmSpec.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/arrow/core/raise/TraceJvmSpec.kt index 94d3d50c740..bfe034192cb 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/arrow/core/raise/TraceJvmSpec.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/arrow/core/raise/TraceJvmSpec.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.test.runTest @OptIn(ExperimentalTraceApi::class) class TraceJvmSpec { @Test fun canTraceATypedError() = runTest { - either { + either { traced({ raise(RuntimeException("")) }) { traced, raised -> // Remove first 2 lines: // arrow.core.raise.RaiseCancellationException diff --git a/arrow-libs/core/arrow-eval/src/commonTest/kotlin/arrow/eval/SuspendEvalTest.kt b/arrow-libs/core/arrow-eval/src/commonTest/kotlin/arrow/eval/SuspendEvalTest.kt index 37d00c01125..6e8c4b44a31 100644 --- a/arrow-libs/core/arrow-eval/src/commonTest/kotlin/arrow/eval/SuspendEvalTest.kt +++ b/arrow-libs/core/arrow-eval/src/commonTest/kotlin/arrow/eval/SuspendEvalTest.kt @@ -6,7 +6,7 @@ import kotlinx.coroutines.test.runTest import kotlin.test.Test internal data class SuspendSideEffect(var counter: Int = 0) { - suspend fun increment() { + fun increment() { counter++ } } diff --git a/arrow-libs/fx/arrow-collectors/src/commonMain/kotlin/arrow/collectors/Collect.kt b/arrow-libs/fx/arrow-collectors/src/commonMain/kotlin/arrow/collectors/Collect.kt index 68e39495526..98567a89446 100644 --- a/arrow-libs/fx/arrow-collectors/src/commonMain/kotlin/arrow/collectors/Collect.kt +++ b/arrow-libs/fx/arrow-collectors/src/commonMain/kotlin/arrow/collectors/Collect.kt @@ -8,8 +8,6 @@ import kotlinx.coroutines.flow.DEFAULT_CONCURRENCY import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.asFlow import kotlinx.coroutines.flow.collect -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.onStart /** * Performs collection over the elements of [this]. @@ -108,23 +106,20 @@ public fun Iterator.collect( ): R = collectI(collector) @OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class) -@Suppress("UNINITIALIZED_VARIABLE", "UNCHECKED_CAST") +@Suppress("UNCHECKED_CAST") internal suspend fun Flow.collectI( collector: CollectorI, concurrency: Int = DEFAULT_CONCURRENCY, ): R { - var accumulator: A - - val started = this.onStart { accumulator = collector.supply() } + val accumulator: A = collector.supply() - val continued = when { + when { collector.has(Characteristics.CONCURRENT, Characteristics.UNORDERED) -> - started.parMapUnordered(concurrency) { collector.accumulate(accumulator, it) } + parMapUnordered(concurrency) { collector.accumulate(accumulator, it) }.collect() collector.has(Characteristics.CONCURRENT) -> - started.parMap(concurrency) { collector.accumulate(accumulator, it) } - else -> started.map { collector.accumulate(accumulator, it) } + parMap(concurrency) { collector.accumulate(accumulator, it) }.collect() + else -> collect { collector.accumulate(accumulator, it) } } - continued.collect() return when { collector.has(Characteristics.IDENTITY_FINISH) -> accumulator as R diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/CyclicBarrier.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/CyclicBarrier.kt index 29e241330b1..236494cedc3 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/CyclicBarrier.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/CyclicBarrier.kt @@ -72,8 +72,7 @@ public class CyclicBarrier(public val capacity: Int, private val barrierAction: barrierAction.invoke() } catch (e: Throwable) { val cancellationException = - if (e is CancellationException) e - else CancellationException("CyclicBarrier barrierAction failed with exception.", e.nonFatalOrThrow()) + e as? CancellationException ?: CancellationException("CyclicBarrier barrierAction failed with exception.", e.nonFatalOrThrow()) unblock.cancel(cancellationException) throw cancellationException } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race2.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race2.kt index d517acffafc..165cc8205fe 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race2.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race2.kt @@ -20,7 +20,7 @@ import kotlin.coroutines.EmptyCoroutineContext * Races the participants [fa], [fb] in parallel on the [Dispatchers.Default]. * The winner of the race cancels the other participants. * Cancelling the operation cancels all participants. - * An [uncancellable] participant will back-pressure the result of [raceN]. + * A [kotlinx.coroutines.NonCancellable] participant will back-pressure the result of [raceN]. * * ```kotlin * import arrow.core.Either @@ -48,7 +48,6 @@ import kotlin.coroutines.EmptyCoroutineContext * @param fa task to participate in the race * @param fb task to participate in the race * @return either [Either.Left] if [fa] won the race, or [Either.Right] if [fb] won the race. - * @see racePair for a version that does not automatically cancel the loser. * @see raceN for the same function that can race on any [CoroutineContext]. */ public suspend inline fun raceN(crossinline fa: suspend CoroutineScope.() -> A, crossinline fb: suspend CoroutineScope.() -> B): Either { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race3.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race3.kt index 7ab2d336670..bfbef36a9b3 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race3.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race3.kt @@ -102,7 +102,7 @@ public suspend inline fun raceN( } @PublishedApi -internal suspend fun cancelAndCompose(first: Deferred<*>, second: Deferred<*>): Unit { +internal suspend fun cancelAndCompose(first: Deferred<*>, second: Deferred<*>) { val e1 = try { first.cancelAndJoin() null diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Generators.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Generators.kt index 61a2565028b..8a205b9203a 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Generators.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Generators.kt @@ -31,7 +31,7 @@ import kotlin.coroutines.startCoroutine fun Arb.Companion.flow(arbA: Arb, range: IntRange = 1 .. 20): Arb> = Arb.choose( 10 to Arb.list(arbA, range).map { it.asFlow() }, - 10 to Arb.list(arbA, range).map { channelFlow { it.forEach { send(it) } }.buffer(Channel.RENDEZVOUS) }, + 10 to Arb.list(arbA, range).map { l -> channelFlow { l.forEach { send(it) } }.buffer(Channel.RENDEZVOUS) }, 1 to Arb.constant(emptyFlow()), ) @@ -153,7 +153,7 @@ inline fun assertThrowable(executable: () -> A): Throwable { e } - return if (a is Throwable) a else fail("Expected an exception but found: $a") + return a as? Throwable ?: fail("Expected an exception but found: $a") } suspend fun CompletableDeferred.shouldHaveCompleted(): T { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt index 2a6be9e56f7..9c783b6a3ed 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt @@ -13,7 +13,6 @@ import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import kotlin.test.Test -import kotlin.time.Duration.Companion.seconds class ParZip3JvmTest { @Test fun parZip3ReturnsToOriginalContext(): Unit = runBlocking(Dispatchers.Default) { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt index dbb38c9be6c..5a2d0c054a9 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt @@ -14,7 +14,6 @@ import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import kotlin.test.Test -import kotlin.time.Duration.Companion.seconds class ParZip4JvmTest { @Test fun parZip4ReturnsToOriginalContext(): Unit = runBlocking(Dispatchers.Default) { diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TMVar.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TMVar.kt index 14c60174f56..2f6b3d051f1 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TMVar.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TMVar.kt @@ -1,7 +1,7 @@ package arrow.fx.stm -public fun STM.newTMVar(a: A): TMVar = TMVar(newTVar(Option.Some(a))) -public fun STM.newEmptyTMVar(): TMVar = TMVar(newTVar(Option.None)) +public fun STM.newTMVar(a: A): TMVar = TMVar(newTVar(Option.Some(a))) +public fun STM.newEmptyTMVar(): TMVar = TMVar(newTVar(Option.None)) /** * A [TMVar] is a mutable reference that can either be empty or hold a value. @@ -181,8 +181,8 @@ public fun STM.newEmptyTMVar(): TMVar = TMVar(newTVar(Option.None)) */ public data class TMVar internal constructor(internal val v: TVar>) { public companion object { - public suspend fun new(a: A): TMVar = TMVar(TVar.new(Option.Some(a))) - public suspend fun empty(): TMVar = TMVar(TVar.new(Option.None)) + public suspend fun new(a: A): TMVar = TMVar(TVar.new(Option.Some(a))) + public suspend fun empty(): TMVar = TMVar(TVar.new(Option.None)) } } diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TVar.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TVar.kt index 9b47ea2ac16..900a3d048dd 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TVar.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TVar.kt @@ -181,7 +181,7 @@ public class TVar internal constructor(a: A) { * If [frame] no longer has the lock (a write happened and now read * tries to unlock) it is ignored */ - internal fun release(frame: STMFrame, a: A): Unit { + internal fun release(frame: STMFrame, a: A) { ref.compareAndSet(frame, a as Any?) } @@ -212,14 +212,14 @@ public class TVar internal constructor(a: A) { /** * A transaction resumed so remove it from the [TVar] */ - internal fun removeWaiting(trans: STMTransaction): Unit { - waiting.update { it.filter { it !== trans } } + internal fun removeWaiting(trans: STMTransaction) { + waiting.update { l -> l.filter { it !== trans } } } /** * Resume execution of all transactions waiting for this [TVar] to change. */ - internal fun notify(): Unit { + internal fun notify() { waiting.getAndSet(emptyList()).forEach { it.getCont()?.resume(Unit) } } diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/STMTest.kt b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/STMTest.kt index 16aeeec5b39..52443db7fb8 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/STMTest.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/STMTest.kt @@ -247,7 +247,7 @@ class STMTest { delay(20.milliseconds) atomically { acc1.modify { it + 60 } } }, - { _, _ -> Unit } + { _, _ -> } ) acc1.unsafeRead() shouldBeExactly 50 acc2.unsafeRead() shouldBeExactly 250 @@ -277,7 +277,7 @@ class STMTest { }, { val collected = mutableSetOf() - for (i in 1..100) { + repeat(100) { // consumer atomically { tq.read().also { it shouldBeInRange (1..100) } @@ -286,7 +286,7 @@ class STMTest { // verify that we got 100 unique numbers collected.size shouldBeExactly 100 } - ) { _, _ -> Unit } + ) { _, _ -> } // the above only finishes if the consumer reads at least 100 values, this here is just to make sure there are no leftovers atomically { tq.flush() } shouldBe emptyList() } diff --git a/arrow-libs/integrations/arrow-core-serialization/src/commonTest/kotlin/arrow/core/serialization/ModuleTest.kt b/arrow-libs/integrations/arrow-core-serialization/src/commonTest/kotlin/arrow/core/serialization/ModuleTest.kt index b4c4a3360ce..c96270c4e60 100644 --- a/arrow-libs/integrations/arrow-core-serialization/src/commonTest/kotlin/arrow/core/serialization/ModuleTest.kt +++ b/arrow-libs/integrations/arrow-core-serialization/src/commonTest/kotlin/arrow/core/serialization/ModuleTest.kt @@ -1,18 +1,13 @@ package arrow.core.serialization import arrow.core.* -import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.map import io.kotest.property.arbitrary.string import kotlinx.serialization.Contextual import kotlinx.serialization.Serializable -import kotlinx.serialization.builtins.nullable -import kotlinx.serialization.builtins.serializer import kotlinx.serialization.json.Json -import kotlinx.serialization.json.decodeFromJsonElement -import kotlinx.serialization.json.encodeToJsonElement import kotlinx.serialization.modules.SerializersModule import kotlin.test.Test diff --git a/arrow-libs/integrations/arrow-raise-ktor-server/api/android/arrow-raise-ktor-server.api b/arrow-libs/integrations/arrow-raise-ktor-server/api/android/arrow-raise-ktor-server.api index 021c76e89ac..4d37ff6b389 100644 --- a/arrow-libs/integrations/arrow-raise-ktor-server/api/android/arrow-raise-ktor-server.api +++ b/arrow-libs/integrations/arrow-raise-ktor-server/api/android/arrow-raise-ktor-server.api @@ -60,12 +60,12 @@ public final class arrow/raise/ktor/server/RaiseAccumulate$Error : arrow/raise/k } public final class arrow/raise/ktor/server/RaiseAccumulate$Ok : arrow/raise/ktor/server/RaiseAccumulate$Value { - public fun (Larrow/raise/ktor/server/RaiseAccumulate;Ljava/lang/Object;)V + public fun (Ljava/lang/Object;)V public fun getResult ()Ljava/lang/Object; } public abstract class arrow/raise/ktor/server/RaiseAccumulate$Value { - public fun (Larrow/raise/ktor/server/RaiseAccumulate;)V + public fun ()V public abstract fun getResult ()Ljava/lang/Object; public final fun getValue (Ljava/lang/Void;Lkotlin/reflect/KProperty;)Ljava/lang/Object; } diff --git a/arrow-libs/integrations/arrow-raise-ktor-server/api/arrow-raise-ktor-server.klib.api b/arrow-libs/integrations/arrow-raise-ktor-server/api/arrow-raise-ktor-server.klib.api index 453aacc2e53..bcffb4cab04 100644 --- a/arrow-libs/integrations/arrow-raise-ktor-server/api/arrow-raise-ktor-server.klib.api +++ b/arrow-libs/integrations/arrow-raise-ktor-server/api/arrow-raise-ktor-server.klib.api @@ -47,20 +47,20 @@ open class <#A: kotlin/Any?> arrow.raise.ktor.server/RaiseAccumulate : arrow.cor final fun (): arrow.core.raise/Raise> // arrow.raise.ktor.server/RaiseAccumulate.raise.|(){}[0] final fun <#A1: kotlin/Any> ensureNotNullOrAccumulate(#A1?, kotlin/Function0<#A>) // arrow.raise.ktor.server/RaiseAccumulate.ensureNotNullOrAccumulate|ensureNotNullOrAccumulate(0:0?;kotlin.Function0<1:0>){0§}[0] - final fun <#A1: kotlin/Any?> (arrow.core/Either<#A, #A1>).bindOrAccumulate(): arrow.raise.ktor.server/RaiseAccumulate.Value<#A1, #A> // arrow.raise.ktor.server/RaiseAccumulate.bindOrAccumulate|bindOrAccumulate@arrow.core.Either<1:0,0:0>(){0§}[0] + final fun <#A1: kotlin/Any?> (arrow.core/Either<#A, #A1>).bindOrAccumulate(): arrow.raise.ktor.server/RaiseAccumulate.Value<#A1> // arrow.raise.ktor.server/RaiseAccumulate.bindOrAccumulate|bindOrAccumulate@arrow.core.Either<1:0,0:0>(){0§}[0] final fun <#A1: kotlin/Any?> (arrow.core/Either, #A1>).bindNel(): #A1 // arrow.raise.ktor.server/RaiseAccumulate.bindNel|bindNel@arrow.core.Either,0:0>(){0§}[0] - final fun <#A1: kotlin/Any?> (arrow.core/Either, #A1>).bindNelOrAccumulate(): arrow.raise.ktor.server/RaiseAccumulate.Value<#A1, #A> // arrow.raise.ktor.server/RaiseAccumulate.bindNelOrAccumulate|bindNelOrAccumulate@arrow.core.Either,0:0>(){0§}[0] - final fun <#A1: kotlin/Any?> (kotlin.collections/Iterable>).bindAllOrAccumulate(): arrow.raise.ktor.server/RaiseAccumulate.Value, #A> // arrow.raise.ktor.server/RaiseAccumulate.bindAllOrAccumulate|bindAllOrAccumulate@kotlin.collections.Iterable>(){0§}[0] + final fun <#A1: kotlin/Any?> (arrow.core/Either, #A1>).bindNelOrAccumulate(): arrow.raise.ktor.server/RaiseAccumulate.Value<#A1> // arrow.raise.ktor.server/RaiseAccumulate.bindNelOrAccumulate|bindNelOrAccumulate@arrow.core.Either,0:0>(){0§}[0] + final fun <#A1: kotlin/Any?> (kotlin.collections/Iterable>).bindAllOrAccumulate(): arrow.raise.ktor.server/RaiseAccumulate.Value> // arrow.raise.ktor.server/RaiseAccumulate.bindAllOrAccumulate|bindAllOrAccumulate@kotlin.collections.Iterable>(){0§}[0] final fun addErrors(kotlin.collections/Iterable<#A>) // arrow.raise.ktor.server/RaiseAccumulate.addErrors|addErrors(kotlin.collections.Iterable<1:0>){}[0] final fun ensureOrAccumulate(kotlin/Boolean, kotlin/Function0<#A>) // arrow.raise.ktor.server/RaiseAccumulate.ensureOrAccumulate|ensureOrAccumulate(kotlin.Boolean;kotlin.Function0<1:0>){}[0] final fun hasErrors(): kotlin/Boolean // arrow.raise.ktor.server/RaiseAccumulate.hasErrors|hasErrors(){}[0] final fun raiseErrors(): kotlin/Nothing // arrow.raise.ktor.server/RaiseAccumulate.raiseErrors|raiseErrors(){}[0] - final inline fun <#A1: kotlin/Any?> accumulating(kotlin/Function1, #A1>): arrow.raise.ktor.server/RaiseAccumulate.Value<#A1, #A> // arrow.raise.ktor.server/RaiseAccumulate.accumulating|accumulating(kotlin.Function1,0:0>){0§}[0] + final inline fun <#A1: kotlin/Any?> accumulating(kotlin/Function1, #A1>): arrow.raise.ktor.server/RaiseAccumulate.Value<#A1> // arrow.raise.ktor.server/RaiseAccumulate.accumulating|accumulating(kotlin.Function1,0:0>){0§}[0] final inline fun <#A1: kotlin/Any?> withNel(kotlin/Function1>, #A1>): #A1 // arrow.raise.ktor.server/RaiseAccumulate.withNel|withNel(kotlin.Function1>,0:0>){0§}[0] open fun <#A1: kotlin/Any?, #B1: kotlin/Any?> (kotlin.collections/Map<#A1, arrow.core/Either<#A, #B1>>).bindAll(): kotlin.collections/Map<#A1, #B1> // arrow.raise.ktor.server/RaiseAccumulate.bindAll|bindAll@kotlin.collections.Map<0:0,arrow.core.Either<1:0,0:1>>(){0§;1§}[0] open fun raise(#A): kotlin/Nothing // arrow.raise.ktor.server/RaiseAccumulate.raise|raise(1:0){}[0] - abstract inner class <#A1: out kotlin/Any?> Value { // arrow.raise.ktor.server/RaiseAccumulate.Value|null[0] + abstract class <#A1: out kotlin/Any?> Value { // arrow.raise.ktor.server/RaiseAccumulate.Value|null[0] constructor () // arrow.raise.ktor.server/RaiseAccumulate.Value.|(){}[0] abstract val result // arrow.raise.ktor.server/RaiseAccumulate.Value.result|{}result[0] @@ -69,14 +69,14 @@ open class <#A: kotlin/Any?> arrow.raise.ktor.server/RaiseAccumulate : arrow.cor final fun getValue(kotlin/Nothing?, kotlin.reflect/KProperty<*>): #A1 // arrow.raise.ktor.server/RaiseAccumulate.Value.getValue|getValue(kotlin.Nothing?;kotlin.reflect.KProperty<*>){}[0] } - final inner class <#A1: out kotlin/Any?> Ok : arrow.raise.ktor.server/RaiseAccumulate.Value<#A1, #A> { // arrow.raise.ktor.server/RaiseAccumulate.Ok|null[0] + final class <#A1: out kotlin/Any?> Ok : arrow.raise.ktor.server/RaiseAccumulate.Value<#A1> { // arrow.raise.ktor.server/RaiseAccumulate.Ok|null[0] constructor (#A1) // arrow.raise.ktor.server/RaiseAccumulate.Ok.|(1:0){}[0] final val result // arrow.raise.ktor.server/RaiseAccumulate.Ok.result|{}result[0] final fun (): #A1 // arrow.raise.ktor.server/RaiseAccumulate.Ok.result.|(){}[0] } - final inner class Error : arrow.raise.ktor.server/RaiseAccumulate.Value { // arrow.raise.ktor.server/RaiseAccumulate.Error|null[0] + final inner class Error : arrow.raise.ktor.server/RaiseAccumulate.Value { // arrow.raise.ktor.server/RaiseAccumulate.Error|null[0] constructor () // arrow.raise.ktor.server/RaiseAccumulate.Error.|(){}[0] final val result // arrow.raise.ktor.server/RaiseAccumulate.Error.result|{}result[0] diff --git a/arrow-libs/integrations/arrow-raise-ktor-server/api/jvm/arrow-raise-ktor-server.api b/arrow-libs/integrations/arrow-raise-ktor-server/api/jvm/arrow-raise-ktor-server.api index 021c76e89ac..4d37ff6b389 100644 --- a/arrow-libs/integrations/arrow-raise-ktor-server/api/jvm/arrow-raise-ktor-server.api +++ b/arrow-libs/integrations/arrow-raise-ktor-server/api/jvm/arrow-raise-ktor-server.api @@ -60,12 +60,12 @@ public final class arrow/raise/ktor/server/RaiseAccumulate$Error : arrow/raise/k } public final class arrow/raise/ktor/server/RaiseAccumulate$Ok : arrow/raise/ktor/server/RaiseAccumulate$Value { - public fun (Larrow/raise/ktor/server/RaiseAccumulate;Ljava/lang/Object;)V + public fun (Ljava/lang/Object;)V public fun getResult ()Ljava/lang/Object; } public abstract class arrow/raise/ktor/server/RaiseAccumulate$Value { - public fun (Larrow/raise/ktor/server/RaiseAccumulate;)V + public fun ()V public abstract fun getResult ()Ljava/lang/Object; public final fun getValue (Ljava/lang/Void;Lkotlin/reflect/KProperty;)Ljava/lang/Object; } diff --git a/arrow-libs/integrations/arrow-raise-ktor-server/src/commonMain/kotlin/arrow/raise/ktor/server/predef.kt b/arrow-libs/integrations/arrow-raise-ktor-server/src/commonMain/kotlin/arrow/raise/ktor/server/predef.kt index 5ff47b128dc..ba616945a63 100644 --- a/arrow-libs/integrations/arrow-raise-ktor-server/src/commonMain/kotlin/arrow/raise/ktor/server/predef.kt +++ b/arrow-libs/integrations/arrow-raise-ktor-server/src/commonMain/kotlin/arrow/raise/ktor/server/predef.kt @@ -30,7 +30,7 @@ public open class RaiseAccumulate( raise.raise((errors + r).toNonEmptyListOrNull()!!) public override fun Map>.bindAll(): Map = - raise.mapValuesOrAccumulate(this) { it -> it.value.bind() } + raise.mapValuesOrAccumulate(this) { it.value.bind() } @RaiseDSL public fun EitherNel.bindNel(): A = when (this) { @@ -75,7 +75,7 @@ public open class RaiseAccumulate( Error() } - public abstract inner class Value { + public abstract class Value { public abstract val result: A public operator fun getValue(value: Nothing?, property: KProperty<*>): A = result } @@ -87,5 +87,5 @@ public open class RaiseAccumulate( raiseErrors() } } - @PublishedApi internal inner class Ok(override val result: A): Value() + @PublishedApi internal class Ok(override val result: A): Value() } diff --git a/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Flow.kt b/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Flow.kt index 62a0014a412..ef832dd2324 100644 --- a/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Flow.kt +++ b/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Flow.kt @@ -38,7 +38,7 @@ public fun StateFlow.optic(g: Lens): StateFlow = object : Sta /** * Exposes the values of [this] through the optic. - * Any change made to [value] is reflected in the original [MutableStateFlow]. + * Any change made to [MutableStateFlow.value] is reflected in the original [MutableStateFlow]. */ public fun MutableStateFlow.optic(lens: Lens): MutableStateFlow = object : MutableStateFlow { override var value: A diff --git a/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/State.kt b/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/State.kt index d5261c8e58a..767db76b271 100644 --- a/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/State.kt +++ b/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/State.kt @@ -16,7 +16,7 @@ public fun State.optic(g: Lens): State = object : State { /** * Exposes the value of [this] through the optic. - * Any change made to [value] is reflected in the original [MutableState]. + * Any change made to [MutableState.value] is reflected in the original [MutableState]. */ public fun MutableState.optic(lens: Lens): MutableState = object : MutableState { override var value: A diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt index 8cbc696473e..254e19ed093 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt @@ -50,7 +50,7 @@ internal fun KSClassDeclaration.targets(): Set = targetsFromOptics internal fun KSClassDeclaration.targetsFromOpticsAnnotation(): Set = annotations .single { it.annotationType.resolve().declaration.qualifiedName?.asString() == "arrow.optics.optics" } .arguments - .flatMap { (it.value as? ArrayList<*>).orEmpty().mapNotNull { it as? KSType } } + .flatMap { (it.value as? ArrayList<*>).orEmpty().filterIsInstance() } .mapNotNull { when (it.qualifiedString()) { "arrow.optics.OpticsTarget.ISO" -> OpticsTarget.ISO diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/CopyTest.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/CopyTest.kt index 76084dd7ff9..31ea38af67f 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/CopyTest.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/CopyTest.kt @@ -5,7 +5,7 @@ import kotlin.test.Test // from https://kotlinlang.slack.com/archives/C5UPMM0A0/p1688822411819599 // and https://github.com/overfullstack/my-lab/blob/master/arrow/src/test/kotlin/ga/overfullstack/optics/OpticsLab.kt -val copyCode = """ +const val copyCode = """ @optics data class Person(val name: String, val age: Int, val address: Address) { companion object } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt index 2104645de87..c47e94ad093 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt @@ -92,8 +92,8 @@ public interface PPrism : POptional { PPrism( { it.fold( - { a -> getOrModify(a).mapLeft { l -> Either.Left(l) }.map { r -> Either.Left(r) } }, - { c -> Either.Right(Either.Right(c)) }) + { a -> getOrModify(a).mapLeft { l -> Left(l) }.map { r -> Left(r) } }, + { c -> Right(Right(c)) }) }, { when (it) { @@ -110,8 +110,8 @@ public interface PPrism : POptional { PPrism( { it.fold( - { c -> Either.Right(Either.Left(c)) }, - { s -> getOrModify(s).mapLeft { l -> Either.Right(l) }.map { r -> Either.Right(r) } }) + { c -> Right(Left(c)) }, + { s -> getOrModify(s).mapLeft { l -> Right(l) }.map { r -> Right(r) } }) }, { it.map(this::reverseGet) } ) @@ -201,8 +201,8 @@ public interface PPrism : POptional { Prism( getOrModify = { e -> when (e) { - is Either.Left -> e.value.right() - is Either.Right -> e.left() + is Left -> e.value.right() + is Right -> e.left() } }, reverseGet = { it.left() } @@ -216,8 +216,8 @@ public interface PPrism : POptional { PPrism( getOrModify = { e -> when (e) { - is Either.Left -> e.left() - is Either.Right -> e.value.right() + is Left -> e.left() + is Right -> e.value.right() } }, reverseGet = { it.right() } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt index 05b2cb2e61d..82836f33df1 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt @@ -4,7 +4,6 @@ import arrow.core.Either import arrow.core.NonEmptyList import arrow.core.Option import arrow.optics.Every -import arrow.optics.Optional import arrow.optics.Traversal import kotlin.jvm.JvmName diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/filterIndex.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/filterIndex.kt index 299494fe7f9..cc7c9ba0c8e 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/filterIndex.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/filterIndex.kt @@ -12,7 +12,7 @@ import kotlin.jvm.JvmName * * @receiver [Optional] with a focus in [S] * @param filter [FilterIndex] instance to provide a [Optional] to focus into [S] at [I] - * @param i index [I] to focus into [S] and find focus [A] + * @param predicate index [I] to focus into [S] and find focus [A] * @return [Optional] with a focus in [A] at given index [I] */ public fun Traversal.filterIndex(filter: FilterIndex, predicate: Predicate): Traversal = diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/CopyTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/CopyTest.kt index 6a406d861b5..2993dcde5b7 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/CopyTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/CopyTest.kt @@ -104,7 +104,7 @@ class CopyTest { 35, Address(Street("Kotlinstraat", 1), City("Hilversum", "Netherlands"), listOf(1, 2)) ) - val meAfterMoving1 = me.moveToAmsterdamInside() + val meAfterMoving1 = me.moveToAmsterdamCopy() val meAfterMoving2 = me.moveToAmsterdamInside() meAfterMoving1 shouldBe meAfterMoving2 meAfterMoving1.address.city.name shouldBe "Amsterdam" diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/dsl/AtSyntaxTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/dsl/AtSyntaxTest.kt index c7178a169fa..4a8c1d0e5d8 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/dsl/AtSyntaxTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/dsl/AtSyntaxTest.kt @@ -29,6 +29,7 @@ class AtSyntaxTest { assertEquals(expected, actual) } + @Test fun setKeep() { val original = setOf(1) val expected = Wrapper(setOf(1, 2)) diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/dsl/EverySyntaxTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/dsl/EverySyntaxTest.kt index de9894af25f..f98fe9b1f57 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/dsl/EverySyntaxTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/dsl/EverySyntaxTest.kt @@ -1,8 +1,6 @@ package arrow.optics.dsl import arrow.core.* -import arrow.optics.Lens -import kotlin.jvm.JvmInline import kotlin.test.Test import kotlin.test.assertEquals diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/Laws.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/Laws.kt index 8f057f3bd68..1441a16c4e0 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/Laws.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/Laws.kt @@ -1,7 +1,6 @@ package arrow.optics.test.laws import io.kotest.assertions.fail -import io.kotest.assertions.withClue import kotlinx.coroutines.test.TestResult import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runTest diff --git a/arrow-libs/resilience/arrow-resilience/api/android/arrow-resilience.api b/arrow-libs/resilience/arrow-resilience/api/android/arrow-resilience.api index a46f4c489b3..1d408f21525 100644 --- a/arrow-libs/resilience/arrow-resilience/api/android/arrow-resilience.api +++ b/arrow-libs/resilience/arrow-resilience/api/android/arrow-resilience.api @@ -89,6 +89,7 @@ public final class arrow/resilience/CircuitBreaker$State$Open : arrow/resilience public fun getOpeningStrategy ()Larrow/resilience/CircuitBreaker$OpeningStrategy; public final fun getResetTimeout-UwyO8pc ()J public final fun getStartedAt ()Lkotlin/time/TimeMark; + public fun hashCode ()I public fun toString ()Ljava/lang/String; } diff --git a/arrow-libs/resilience/arrow-resilience/api/arrow-resilience.klib.api b/arrow-libs/resilience/arrow-resilience/api/arrow-resilience.klib.api index b9d2e9f213b..5be56a48afb 100644 --- a/arrow-libs/resilience/arrow-resilience/api/arrow-resilience.klib.api +++ b/arrow-libs/resilience/arrow-resilience/api/arrow-resilience.klib.api @@ -205,6 +205,7 @@ final class arrow.resilience/CircuitBreaker { // arrow.resilience/CircuitBreaker final fun (): kotlin.time/TimeMark // arrow.resilience/CircuitBreaker.State.Open.startedAt.|(){}[0] final fun equals(kotlin/Any?): kotlin/Boolean // arrow.resilience/CircuitBreaker.State.Open.equals|equals(kotlin.Any?){}[0] + final fun hashCode(): kotlin/Int // arrow.resilience/CircuitBreaker.State.Open.hashCode|hashCode(){}[0] final fun toString(): kotlin/String // arrow.resilience/CircuitBreaker.State.Open.toString|toString(){}[0] } } diff --git a/arrow-libs/resilience/arrow-resilience/api/jvm/arrow-resilience.api b/arrow-libs/resilience/arrow-resilience/api/jvm/arrow-resilience.api index a46f4c489b3..1d408f21525 100644 --- a/arrow-libs/resilience/arrow-resilience/api/jvm/arrow-resilience.api +++ b/arrow-libs/resilience/arrow-resilience/api/jvm/arrow-resilience.api @@ -89,6 +89,7 @@ public final class arrow/resilience/CircuitBreaker$State$Open : arrow/resilience public fun getOpeningStrategy ()Larrow/resilience/CircuitBreaker$OpeningStrategy; public final fun getResetTimeout-UwyO8pc ()J public final fun getStartedAt ()Lkotlin/time/TimeMark; + public fun hashCode ()I public fun toString ()Ljava/lang/String; } diff --git a/arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/CircuitBreaker.kt b/arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/CircuitBreaker.kt index 9260dd08999..eb63284b096 100644 --- a/arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/CircuitBreaker.kt +++ b/arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/CircuitBreaker.kt @@ -145,6 +145,7 @@ private constructor( ) { /** Returns the current [State], meant for debugging purposes.*/ + @Suppress("RedundantSuspendModifier") public suspend fun state(): State = state.get() /** @@ -453,6 +454,12 @@ private constructor( override fun toString(): String = "CircuitBreaker.State.Open(startedAt=$startedAt, resetTimeoutNanos=$resetTimeout, expiresAt=$expiresAt)" + + override fun hashCode(): Int { + var result = startedAt.hashCode() + result = 31 * result + resetTimeout.hashCode() + return result + } } /** diff --git a/arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/Saga.kt b/arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/Saga.kt index ae8190c4fcc..c38831bdd0a 100644 --- a/arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/Saga.kt +++ b/arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/Saga.kt @@ -1,7 +1,7 @@ package arrow.resilience import arrow.atomic.Atomic -import arrow.atomic.update +import arrow.atomic.updateAndGet import arrow.core.nonFatalOrThrow import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.withContext @@ -133,10 +133,7 @@ internal class SagaBuilder( // the compensation stack will run in the `transact` stage, this is just the builder when (res) { null -> Unit - else -> stack.update( - function = { listOf(suspend { compensation(res) }) + it }, - transform = { _, new -> new } - ) + else -> stack.updateAndGet { listOf(suspend { compensation(res) }) + it } } } diff --git a/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/CircuitBreakerTest.kt b/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/CircuitBreakerTest.kt index c1f0e3c87fa..9501a2729cf 100644 --- a/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/CircuitBreakerTest.kt +++ b/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/CircuitBreakerTest.kt @@ -79,7 +79,7 @@ class CircuitBreakerTest { @Test fun circuitBreakerOpensAfterMaxFailures(): TestResult = runTest { - val cb = CircuitBreaker(resetTimeout = resetTimeout, openingStrategy = OpeningStrategy.Count(maxFailures),) + val cb = CircuitBreaker(resetTimeout = resetTimeout, openingStrategy = OpeningStrategy.Count(maxFailures)) val result = recurAndCollect>(4).repeat { Either.catch { cb.protectOrThrow { throw dummy } } diff --git a/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/ScheduleTest.kt b/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/ScheduleTest.kt index 6a4933181e7..49a9dd85d5c 100644 --- a/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/ScheduleTest.kt +++ b/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/ScheduleTest.kt @@ -358,7 +358,7 @@ class ScheduleTest { assertThrows { Schedule.forever() - .retry { if (count++ == 0) throw ex else 1 } + .retry { if (count++ == 0) throw ex } } } @@ -367,7 +367,7 @@ class ScheduleTest { val count = AtomicLong(0) val iterations = stackSafeIteration().toLong() - suspend fun increment() { + fun increment() { count.incrementAndGet() } @@ -392,7 +392,7 @@ class ScheduleTest { val count = AtomicLong(0) val iterations = stackSafeIteration().toLong() - suspend fun increment() { + fun increment() { count.incrementAndGet() } diff --git a/arrow-libs/suspendapp/suspendapp-test-runner/src/test/kotlin/JsSpec.kt b/arrow-libs/suspendapp/suspendapp-test-runner/src/test/kotlin/JsSpec.kt index 8ee50ba8f28..0328e2af57d 100644 --- a/arrow-libs/suspendapp/suspendapp-test-runner/src/test/kotlin/JsSpec.kt +++ b/arrow-libs/suspendapp/suspendapp-test-runner/src/test/kotlin/JsSpec.kt @@ -14,6 +14,7 @@ open class JsSpec : SuspendAppTest() { companion object { val config = JsTestConfig("jsNodeRun") + @Suppress("unused") @JvmStatic fun enabled() = config.validConfig() } diff --git a/arrow-libs/suspendapp/suspendapp-test-runner/src/test/kotlin/JvmSpec.kt b/arrow-libs/suspendapp/suspendapp-test-runner/src/test/kotlin/JvmSpec.kt index fb3740ddb84..f3574f2934d 100644 --- a/arrow-libs/suspendapp/suspendapp-test-runner/src/test/kotlin/JvmSpec.kt +++ b/arrow-libs/suspendapp/suspendapp-test-runner/src/test/kotlin/JvmSpec.kt @@ -12,6 +12,7 @@ class JvmSpec : SuspendAppTest() { val java = ProcessHandle.current().info().command().getOrNull() val jar = System.getProperty("jvmJar")?.let(::Path) + @Suppress("unused") @JvmStatic fun enabled() = java != null && jar?.exists() ?: false } diff --git a/arrow-libs/suspendapp/suspendapp-test-runner/src/test/kotlin/NativeSpec.kt b/arrow-libs/suspendapp/suspendapp-test-runner/src/test/kotlin/NativeSpec.kt index ba0fe00c59c..ab226a0f116 100644 --- a/arrow-libs/suspendapp/suspendapp-test-runner/src/test/kotlin/NativeSpec.kt +++ b/arrow-libs/suspendapp/suspendapp-test-runner/src/test/kotlin/NativeSpec.kt @@ -19,6 +19,7 @@ class NativeSpec : SuspendAppTest() { println("Running native tests... $executable in $workdir...") } + @Suppress("unused") @JvmStatic fun enabled() = (executable?.exists() ?: false) && (workdir?.exists() ?: false) } diff --git a/arrow-libs/suspendapp/suspendapp-test-runner/src/test/kotlin/WasmJsSpec.kt b/arrow-libs/suspendapp/suspendapp-test-runner/src/test/kotlin/WasmJsSpec.kt index 94df65af6be..183b1c708ac 100644 --- a/arrow-libs/suspendapp/suspendapp-test-runner/src/test/kotlin/WasmJsSpec.kt +++ b/arrow-libs/suspendapp/suspendapp-test-runner/src/test/kotlin/WasmJsSpec.kt @@ -7,6 +7,7 @@ class WasmJsSpec : JsSpec() { companion object { val config = JsTestConfig("wasmJsNodeRun") + @Suppress("unused") @JvmStatic fun enabled() = config.validConfig() }