Skip to content

Commit

Permalink
Merge branch 'main' into fd-option-API
Browse files Browse the repository at this point in the history
  • Loading branch information
nomisRev authored Feb 3, 2023
2 parents cfea2b4 + 33828a4 commit 9a4e423
Show file tree
Hide file tree
Showing 8 changed files with 519 additions and 1 deletion.
41 changes: 41 additions & 0 deletions arrow-libs/core/arrow-core/api/arrow-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,47 @@ public final class arrow/core/NonEmptyListKt {
public static final fun unzip (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair;
}

public final class arrow/core/NonEmptySet : java/util/Set, kotlin/jvm/internal/markers/KMappedMarker {
public fun add (Ljava/lang/Object;)Z
public fun addAll (Ljava/util/Collection;)Z
public static final synthetic fun box-impl (Ljava/util/Set;)Larrow/core/NonEmptySet;
public fun clear ()V
public static fun constructor-impl (Ljava/lang/Object;Ljava/util/Set;)Ljava/util/Set;
public fun contains (Ljava/lang/Object;)Z
public static fun contains-impl (Ljava/util/Set;Ljava/lang/Object;)Z
public fun containsAll (Ljava/util/Collection;)Z
public static fun containsAll-impl (Ljava/util/Set;Ljava/util/Collection;)Z
public fun equals (Ljava/lang/Object;)Z
public static fun equals-impl (Ljava/util/Set;Ljava/lang/Object;)Z
public static final fun equals-impl0 (Ljava/util/Set;Ljava/util/Set;)Z
public fun getSize ()I
public static fun getSize-impl (Ljava/util/Set;)I
public fun hashCode ()I
public static fun hashCode-impl (Ljava/util/Set;)I
public fun isEmpty ()Z
public static fun isEmpty-impl (Ljava/util/Set;)Z
public fun iterator ()Ljava/util/Iterator;
public static fun iterator-impl (Ljava/util/Set;)Ljava/util/Iterator;
public static final fun map-J9TPrxk (Ljava/util/Set;Lkotlin/jvm/functions/Function1;)Ljava/util/Set;
public static final fun plus-J9TPrxk (Ljava/util/Set;Ljava/lang/Object;)Ljava/util/Set;
public static final fun plus-J9TPrxk (Ljava/util/Set;Ljava/util/Set;)Ljava/util/Set;
public fun remove (Ljava/lang/Object;)Z
public fun removeAll (Ljava/util/Collection;)Z
public fun retainAll (Ljava/util/Collection;)Z
public synthetic fun size ()I
public fun toArray ()[Ljava/lang/Object;
public fun toArray ([Ljava/lang/Object;)[Ljava/lang/Object;
public fun toString ()Ljava/lang/String;
public static fun toString-impl (Ljava/util/Set;)Ljava/lang/String;
public final synthetic fun unbox-impl ()Ljava/util/Set;
}

public final class arrow/core/NonEmptySetKt {
public static final fun nonEmptySetOf (Ljava/lang/Object;[Ljava/lang/Object;)Ljava/util/Set;
public static final fun toNonEmptySetOrNone (Ljava/util/Collection;)Larrow/core/Option;
public static final fun toNonEmptySetOrNull (Ljava/util/Collection;)Ljava/util/Set;
}

public final class arrow/core/NonFatalKt {
public static final fun NonFatal (Ljava/lang/Throwable;)Z
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package arrow.core

import kotlin.jvm.JvmInline

@JvmInline
public value class NonEmptySet<out T> private constructor(
private val elements: Set<T>
) : Set<T> by elements {

public constructor(first: T, rest: Set<T>) : this(setOf(first) + rest)

public operator fun plus(set: Set<@UnsafeVariance T>): NonEmptySet<T> =
NonEmptySet(elements + set)

public operator fun plus(element: @UnsafeVariance T): NonEmptySet<T> =
NonEmptySet(elements + element)

public fun <R> map(transform: (@UnsafeVariance T) -> R): NonEmptySet<R> =
NonEmptySet(elements.mapTo(mutableSetOf(), transform))

override fun isEmpty(): Boolean = false

override fun toString(): String = "NonEmptySet(${this.joinToString()})"

@Suppress("RESERVED_MEMBER_INSIDE_VALUE_CLASS")
override fun equals(other: Any?): Boolean = when (other) {
is NonEmptySet<*> -> elements == other.elements
else -> elements == other
}

@Suppress("RESERVED_MEMBER_INSIDE_VALUE_CLASS")
override fun hashCode(): Int =
elements.hashCode()
}

public fun <T> nonEmptySetOf(first: T, vararg rest: T): NonEmptySet<T> =
NonEmptySet(first, rest.toSet())

public fun <T> Collection<T>.toNonEmptySetOrNull(): NonEmptySet<T>? =
firstOrNull()?.let { NonEmptySet(it, minus(it).toSet()) }

public fun <T> Collection<T>.toNonEmptySetOrNone(): Option<NonEmptySet<T>> =
toNonEmptySetOrNull().toOption()
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package arrow.core

import arrow.core.test.nonEmptySet
import io.kotest.assertions.withClue
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.booleans.shouldBeTrue
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
import io.kotest.property.Arb
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.next
import io.kotest.property.checkAll

class NonEmptySetTest : StringSpec({

"iterable.toNonEmptySetOrNull should round trip" {
checkAll(Arb.nonEmptySet(Arb.int())) { nonEmptySet ->
nonEmptySet.toNonEmptySetOrNull().shouldNotBeNull() shouldBe nonEmptySet
}
}

"iterable.toNonEmptySetOrNone should round trip" {
checkAll(Arb.nonEmptySet(Arb.int())) { nonEmptySet ->
nonEmptySet.toNonEmptySetOrNone() shouldBe nonEmptySet.some()
}
}

"emptyList.toNonEmptySetOrNull should be null" {
listOf<Int>().toNonEmptySetOrNull() shouldBe null
}

"emptyList.toNonEmptySetOrNone should be none" {
listOf<Int>().toNonEmptySetOrNone() shouldBe none()
}

"adding an element already present doesn't change the set" {
val element = Arb.int().next()
val initialSet: NonEmptySet<Int> = nonEmptySetOf(element) + Arb.nonEmptySet(Arb.int()).next()
initialSet.plus(element) shouldBe initialSet
}
"NonEmptySet equals Set" {
checkAll(
Arb.nonEmptySet(Arb.int())
) { nes ->
val s = nes.toSet()
withClue("$nes should be equal to $s") {
(nes == s).shouldBeTrue() // `shouldBe` doesn't use the `equals` methods on `Iterable`
nes.hashCode() shouldBe s.hashCode()
}
}
}
})

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import arrow.core.Endo
import arrow.core.Eval
import arrow.core.Ior
import arrow.core.NonEmptyList
import arrow.core.NonEmptySet
import arrow.core.Option
import arrow.core.Validated
import arrow.core.left
import arrow.core.right
import arrow.core.toNonEmptySetOrNull
import arrow.core.toOption
import io.kotest.property.Arb
import io.kotest.property.arbitrary.bind
Expand All @@ -17,12 +19,14 @@ import io.kotest.property.arbitrary.choice
import io.kotest.property.arbitrary.constant
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.list
import io.kotest.property.arbitrary.set
import io.kotest.property.arbitrary.long
import io.kotest.property.arbitrary.map
import io.kotest.property.arbitrary.of
import io.kotest.property.arbitrary.orNull
import io.kotest.property.arbitrary.string
import kotlinx.coroutines.Dispatchers
import kotlin.math.max
import kotlin.Result.Companion.failure
import kotlin.Result.Companion.success
import kotlin.coroutines.Continuation
Expand All @@ -36,6 +40,9 @@ import kotlin.coroutines.startCoroutine
fun <A> Arb.Companion.nonEmptyList(arb: Arb<A>, range: IntRange = 0 .. 100): Arb<NonEmptyList<A>> =
Arb.bind(arb, Arb.list(arb, range), ::NonEmptyList)

fun <A> Arb.Companion.nonEmptySet(arb: Arb<A>, range: IntRange = 0 .. 100): Arb<NonEmptySet<A>> =
Arb.set(arb, max(range.first, 1) .. range.last).map { it.toNonEmptySetOrNull()!! }

fun <A> Arb.Companion.sequence(arb: Arb<A>, range: IntRange = 0 .. 100): Arb<Sequence<A>> =
Arb.list(arb, range).map { it.asSequence() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public suspend inline fun <A> guaranteeCase(
} catch (e: CancellationException) {
runReleaseAndRethrow(e) { finalizer(ExitCase.Cancelled(e)) }
} catch (t: Throwable) {
runReleaseAndRethrow(t.nonFatalOrThrow()) { finalizer(ExitCase.Failure(t.nonFatalOrThrow())) }
runReleaseAndRethrow(t.nonFatalOrThrow()) { finalizer(ExitCase.Failure(t)) }
}
withContext(NonCancellable) { finalizer(ExitCase.Completed) }
return res
Expand Down
34 changes: 34 additions & 0 deletions arrow-libs/fx/arrow-fx-resilience/api/arrow-fx-resilience.api
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,40 @@ public final class arrow/fx/resilience/FlowKt {
public static final fun retry (Lkotlinx/coroutines/flow/Flow;Larrow/fx/resilience/Schedule;)Lkotlinx/coroutines/flow/Flow;
}

public final class arrow/fx/resilience/SagaActionStep {
public static final field INSTANCE Larrow/fx/resilience/SagaActionStep;
}

public final class arrow/fx/resilience/SagaBuilder : arrow/fx/resilience/SagaScope {
public fun <init> ()V
public fun <init> (Ljava/util/concurrent/atomic/AtomicReference;)V
public synthetic fun <init> (Ljava/util/concurrent/atomic/AtomicReference;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun saga (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun totalCompensation (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public abstract interface annotation class arrow/fx/resilience/SagaDSLMarker : java/lang/annotation/Annotation {
}

public final class arrow/fx/resilience/SagaKt {
public static final fun saga (Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2;
public static final fun saga (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2;
public static final fun transact (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public abstract interface class arrow/fx/resilience/SagaScope {
public abstract fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun saga (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class arrow/fx/resilience/SagaScope$DefaultImpls {
public static fun bind (Larrow/fx/resilience/SagaScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun invoke (Larrow/fx/resilience/SagaScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public abstract class arrow/fx/resilience/Schedule {
public static final field Companion Larrow/fx/resilience/Schedule$Companion;
public final fun and (Larrow/fx/resilience/Schedule;)Larrow/fx/resilience/Schedule;
Expand Down
Loading

0 comments on commit 9a4e423

Please sign in to comment.