Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlin.annotation.AnnotationTarget.CLASS
/**
* Empty arrays means "Everything that matches annotated class"
*/
public annotation class optics(val targets: Array<OpticsTarget> = emptyArray())
public annotation class optics(val targets: Array<OpticsTarget> = [])

public enum class OpticsTarget {
ISO, LENS, PRISM, OPTIONAL, DSL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -215,7 +218,11 @@ class AutoCloseTest {
}

// copied from Kotest so we can inline it
@OptIn(ExperimentalContracts::class)
inline fun <reified T : Throwable> shouldThrow(block: () -> Any?): T {
contract {
callsInPlace(block, InvocationKind.AT_MOST_ONCE)
}
assertionCounter.inc()
val expectedExceptionClass = T::class
val thrownThrowable = try {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ public fun <A : Comparable<A>> sort(a: A, b: A): Pair<A, A> =

public fun <A : Comparable<A>> sort(a: A, b: A, c: A): Triple<A, A, A> =
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)
}

Expand All @@ -33,9 +33,9 @@ public fun sort(a: Byte, b: Byte): Pair<Byte, Byte> =

public fun sort(a: Byte, b: Byte, c: Byte): Triple<Byte, Byte, Byte> =
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)
}

Expand All @@ -47,9 +47,9 @@ public fun sort(a: Short, b: Short): Pair<Short, Short> =

public fun sort(a: Short, b: Short, c: Short): Triple<Short, Short, Short> =
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)
}

Expand All @@ -61,9 +61,9 @@ public fun sort(a: Int, b: Int): Pair<Int, Int> =

public fun sort(a: Int, b: Int, c: Int): Triple<Int, Int, Int> =
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)
}

Expand All @@ -75,9 +75,9 @@ public fun sort(a: Long, b: Long): Pair<Long, Long> =

public fun sort(a: Long, b: Long, c: Long): Triple<Long, Long, Long> =
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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ public sealed class Either<out A, out B> {
/**
* The left side of the disjoint union, as opposed to the [Right] side.
*/
public data class Left<out A> constructor(val value: A) : Either<A, Nothing>() {
public data class Left<out A>(val value: A) : Either<A, Nothing>() {
override fun toString(): String = "Either.Left($value)"

public companion object
Expand All @@ -786,7 +786,7 @@ public sealed class Either<out A, out B> {
/**
* The right side of the disjoint union, as opposed to the [Left] side.
*/
public data class Right<out B> constructor(val value: B) : Either<Nothing, B>() {
public data class Right<out B>(val value: B) : Either<Nothing, B>() {
override fun toString(): String = "Either.Right($value)"

public companion object {
Expand Down
48 changes: 24 additions & 24 deletions arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public sealed class Ior<out A, out B> {
*/
public fun isLeft(): Boolean {
contract {
returns(true) implies (this@Ior is Ior.Left<A>)
returns(false) implies (this@Ior is Ior.Right<B> || this@Ior is Ior.Both<A, B>)
returns(true) implies (this@Ior is Left<A>)
returns(false) implies (this@Ior is Right<B> || this@Ior is Both<A, B>)
}
return this@Ior is Ior.Left<A>
return this@Ior is Left<A>
}

/**
Expand All @@ -75,10 +75,10 @@ public sealed class Ior<out A, out B> {
*/
public fun isRight(): Boolean {
contract {
returns(true) implies (this@Ior is Ior.Right<B>)
returns(false) implies (this@Ior is Ior.Left<A> || this@Ior is Ior.Both<A, B>)
returns(true) implies (this@Ior is Right<B>)
returns(false) implies (this@Ior is Left<A> || this@Ior is Both<A, B>)
}
return this@Ior is Ior.Right<B>
return this@Ior is Right<B>
}

/**
Expand All @@ -98,10 +98,10 @@ public sealed class Ior<out A, out B> {
*/
public fun isBoth(): Boolean {
contract {
returns(false) implies (this@Ior is Ior.Right<B> || this@Ior is Ior.Left<A>)
returns(true) implies (this@Ior is Ior.Both<A, B>)
returns(false) implies (this@Ior is Right<B> || this@Ior is Left<A>)
returns(true) implies (this@Ior is Both<A, B>)
}
return this@Ior is Ior.Both<A, B>
return this@Ior is Both<A, B>
}

public companion object {
Expand Down Expand Up @@ -451,34 +451,34 @@ public inline fun <A, B> Ior<A, B>.getOrElse(default: (A) -> B): B {
}


public fun <A, B> Pair<A, B>.bothIor(): Ior<A, B> = Ior.Both(this.first, this.second)
public fun <A, B> Pair<A, B>.bothIor(): Ior<A, B> = Both(this.first, this.second)

public fun <A> A.leftIor(): Ior<A, Nothing> = Ior.Left(this)
public fun <A> A.leftIor(): Ior<A, Nothing> = Left(this)

public fun <A> A.rightIor(): Ior<Nothing, A> = Ior.Right(this)
public fun <A> A.rightIor(): Ior<Nothing, A> = Right(this)

public inline fun <A, B> Ior<A, B>.combine(other: Ior<A, B>, combineA: (A, A) -> A, combineB: (B, B) -> B): Ior<A, B> {
contract {
callsInPlace(combineA, InvocationKind.AT_MOST_ONCE)
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))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<out E> internal constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,3 @@ public operator fun <A, B, C, D, E, F> Tuple5<A, B, C, D, E>.plus(f: F): Tuple6<
public operator fun <A, B, C, D, E, F, G> Tuple6<A, B, C, D, E, F>.plus(g: G): Tuple7<A, B, C, D, E, F, G> = Tuple7(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, g)
public operator fun <A, B, C, D, E, F, G, H> Tuple7<A, B, C, D, E, F, G>.plus(h: H): Tuple8<A, B, C, D, E, F, G, H> = Tuple8(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, h)
public operator fun <A, B, C, D, E, F, G, H, I> Tuple8<A, B, C, D, E, F, G, H>.plus(i: I): Tuple9<A, B, C, D, E, F, G, H, I> = 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading