Skip to content

Commit

Permalink
Merge branch 'arrow-2' into atomic-boolean-inline
Browse files Browse the repository at this point in the history
  • Loading branch information
serras authored Oct 28, 2023
2 parents 485aef5 + 1fd3cbf commit dbdb0e6
Show file tree
Hide file tree
Showing 34 changed files with 886 additions and 893 deletions.
10 changes: 0 additions & 10 deletions arrow-libs/core/arrow-annotations/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,10 @@ apply(from = property("ANIMALSNIFFER_MPP"))
kotlin {
sourceSets {
commonMain {
dependencies {
implementation(libs.kotlin.stdlibCommon)
}
}
jvmMain {
dependencies {
implementation(libs.kotlin.stdlib)
}
}
jsMain {
dependencies {
implementation(libs.kotlin.stdlibJS)
}
}
}

jvm {
Expand Down
18 changes: 3 additions & 15 deletions arrow-libs/core/arrow-atomic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,17 @@ kotlin {
sourceSets {
commonMain {
dependencies {
api(libs.kotlin.stdlibCommon)
api(libs.kotlin.stdlib)
}
}

commonTest {
dependencies {
implementation(projects.arrowFxCoroutines)
implementation(libs.kotlin.test)
implementation(libs.coroutines.test)
implementation(libs.kotest.assertionsCore)
implementation(libs.kotest.property)
implementation(libs.coroutines.test)
}
}

jvmMain {
dependencies {
implementation(libs.kotlin.stdlib)
}
}

jsMain {
dependencies {
implementation(libs.kotlin.stdlibJS)
}
}
}
Expand All @@ -64,6 +52,6 @@ tasks.withType<KotlinCompile>().configureEach {
}
}

tasks.test {
tasks.withType<Test> {
useJUnitPlatform()
}
7 changes: 6 additions & 1 deletion arrow-libs/core/arrow-core-retrofit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ plugins {
id(libs.plugins.kotlin.jvm.get().pluginId)
alias(libs.plugins.arrowGradleConfig.kotlin)
alias(libs.plugins.arrowGradleConfig.publish)

alias(libs.plugins.kotlinx.serialization) // Needed for testing only
alias(libs.plugins.kotlinx.kover)
alias(libs.plugins.spotless)
Expand All @@ -24,6 +23,8 @@ dependencies {
compileOnly(libs.squareup.retrofit)

testImplementation(projects.arrowCore)
testImplementation(libs.kotlin.test)
testImplementation(libs.coroutines.test)
testImplementation(libs.kotest.frameworkEngine)
testImplementation(libs.kotest.assertionsCore)
testImplementation(libs.kotest.property)
Expand All @@ -41,3 +42,7 @@ tasks.jar {
attributes["Automatic-Module-Name"] = "arrow.core.retrofit"
}
}

tasks.withType<Test> {
useJUnitPlatform()
}
9 changes: 7 additions & 2 deletions arrow-libs/core/arrow-core-serialization/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ plugins {
id(libs.plugins.kotlin.multiplatform.get().pluginId)
alias(libs.plugins.arrowGradleConfig.kotlin)
alias(libs.plugins.arrowGradleConfig.publish)

alias(libs.plugins.kotest.multiplatform)
id(libs.plugins.kotlinx.serialization.get().pluginId)
}
Expand All @@ -16,14 +15,16 @@ kotlin {
commonMain {
dependencies {
api(projects.arrowCore)
api(libs.kotlin.stdlibCommon)
api(libs.kotlin.stdlib)
api(libs.kotlinx.serializationCore)
}
}

commonTest {
dependencies {
implementation(libs.kotlinx.serializationJson)
implementation(libs.kotlin.test)
implementation(libs.coroutines.test)
implementation(libs.kotest.frameworkEngine)
implementation(libs.kotest.assertionsCore)
implementation(libs.kotest.property)
Expand All @@ -45,3 +46,7 @@ kotlin {
}
}
}

tasks.withType<Test> {
useJUnitPlatform()
}
4 changes: 2 additions & 2 deletions arrow-libs/core/arrow-core/api/arrow-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,9 @@ public final class arrow/core/NonEmptySet : arrow/core/NonEmptyCollection, java/
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/lang/Iterable;)Larrow/core/Option;
public static final fun toNonEmptySetOrNone (Ljava/util/Set;)Larrow/core/Option;
public static final synthetic fun toNonEmptySetOrNone (Ljava/util/Set;)Larrow/core/Option;
public static final fun toNonEmptySetOrNull (Ljava/lang/Iterable;)Ljava/util/Set;
public static final fun toNonEmptySetOrNull (Ljava/util/Set;)Ljava/util/Set;
public static final synthetic fun toNonEmptySetOrNull (Ljava/util/Set;)Ljava/util/Set;
}

public final class arrow/core/NonFatalKt {
Expand Down
28 changes: 11 additions & 17 deletions arrow-libs/core/arrow-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,27 @@ kotlin {
dependencies {
api(projects.arrowAtomic)
api(projects.arrowAnnotations)
api(libs.kotlin.stdlibCommon)
api(libs.kotlin.stdlib)
}
}

commonTest {
dependencies {
implementation(projects.arrowFxCoroutines)
implementation(projects.arrowFunctions)
implementation(libs.kotest.frameworkEngine)
implementation(libs.kotest.assertionsCore)
implementation(libs.kotest.property)
}
implementation(libs.kotlin.test)
implementation(libs.coroutines.test)
implementation(libs.kotest.frameworkEngine)
implementation(libs.kotest.assertionsCore)
implementation(libs.kotest.property)
}
}

jvmTest {
dependencies {
runtimeOnly(libs.kotest.runnerJUnit5)
}
}

jvmMain {
dependencies {
implementation(libs.kotlin.stdlib)
}
}

jsMain {
dependencies {
implementation(libs.kotlin.stdlibJS)
}
}
}

jvm {
Expand All @@ -71,3 +61,7 @@ kotlin {
tasks.named<KotlinCompile>("compileTestKotlinJvm") {
kotlinOptions.freeCompilerArgs += "-Xcontext-receivers"
}

tasks.withType<Test> {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,11 @@ public inline fun <E, A, B> NonEmptyList<A>.mapOrAccumulate(
all.mapOrAccumulate(transform).map { requireNotNull(it.toNonEmptyListOrNull()) }

@JvmName("toNonEmptyListOrNull")
public fun <A> Iterable<A>.toNonEmptyListOrNull(): NonEmptyList<A>? =
toList().let { if (it.isEmpty()) null else NonEmptyList(it) }
public fun <A> Iterable<A>.toNonEmptyListOrNull(): NonEmptyList<A>? {
val iter = iterator()
if (!iter.hasNext()) return null
return NonEmptyList(iter.next(), Iterable { iter }.toList())
}

@JvmName("toNonEmptyListOrNone")
public fun <A> Iterable<A>.toNonEmptyListOrNone(): Option<NonEmptyList<A>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,19 @@ public value class NonEmptySet<out A> private constructor(
public fun <A> nonEmptySetOf(first: A, vararg rest: A): NonEmptySet<A> =
NonEmptySet(first, rest.toSet())

public fun <A> Iterable<A>.toNonEmptySetOrNull(): NonEmptySet<A>? =
firstOrNull()?.let { NonEmptySet(it, minus(it).toSet()) }
public fun <A> Iterable<A>.toNonEmptySetOrNull(): NonEmptySet<A>? {
val iter = iterator()
if (!iter.hasNext()) return null
return NonEmptySet(iter.next(), Iterable { iter }.toSet())
}

public fun <A> Iterable<A>.toNonEmptySetOrNone(): Option<NonEmptySet<A>> =
toNonEmptySetOrNull().toOption()

@Deprecated("Same as Iterable extension", level = DeprecationLevel.HIDDEN)
public fun <A> Set<A>.toNonEmptySetOrNull(): NonEmptySet<A>? =
firstOrNull()?.let { NonEmptySet(it, minus(it)) }
(this as Iterable<A>).toNonEmptySetOrNull()

@Deprecated("Same as Iterable extension", level = DeprecationLevel.HIDDEN)
public fun <A> Set<A>.toNonEmptySetOrNone(): Option<NonEmptySet<A>> =
toNonEmptySetOrNull().toOption()
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.kotest.assertions.withClue
import io.kotest.core.spec.style.StringSpec
import io.kotest.inspectors.shouldForAll
import io.kotest.matchers.booleans.shouldBeTrue
import io.kotest.matchers.nulls.shouldBeNull
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
import io.kotest.property.Arb
Expand All @@ -26,6 +27,16 @@ class NonEmptyListTest : StringSpec({
}
}

"iterable.toNonEmptyListOrNull should return null for an empty iterable" {
listOf<String>().toNonEmptyListOrNull().shouldBeNull()
}

"iterable.toNonEmptyListOrNull should work correctly when the iterable starts with or contains null" {
checkAll(Arb.nonEmptyList(Arb.int().orNull())) { nonEmptyList ->
nonEmptyList.all.toNonEmptyListOrNull().shouldNotBeNull() shouldBe nonEmptyList
}
}

"iterable.toNonEmptyListOrNone should round trip" {
checkAll(Arb.nonEmptyList(Arb.int())) { nonEmptyList ->
nonEmptyList.all.toNonEmptyListOrNone() shouldBe nonEmptyList.some()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,57 @@ 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.shouldBeNull
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.arbitrary.orNull
import io.kotest.property.checkAll
import kotlin.test.Test
import kotlinx.coroutines.test.runTest

class NonEmptySetTest : StringSpec({
class NonEmptySetTest {

"iterable.toNonEmptySetOrNull should round trip" {
@Test fun iterableToNonEmptySetOrNullShouldRoundTrip() = runTest {
checkAll(Arb.nonEmptySet(Arb.int())) { nonEmptySet ->
nonEmptySet.toNonEmptySetOrNull().shouldNotBeNull() shouldBe nonEmptySet
}
}

"iterable.toNonEmptySetOrNone should round trip" {
@Test fun iterableToNonEmptySetOrNullShouldReturnNullForEmptyIterable() = runTest {
listOf<String>().toNonEmptySetOrNull().shouldBeNull()
}

@Test fun iterableToNonEmptySetOrNullShouldReturnWorkWhenContainingNull() = runTest {
checkAll(Arb.nonEmptySet(Arb.int().orNull())) { nonEmptySet ->
nonEmptySet.toNonEmptySetOrNull().shouldNotBeNull() shouldBe nonEmptySet
}
}

@Test fun iterableToNonEmptySetOrNoneShouldRoundTrip() = runTest {
checkAll(Arb.nonEmptySet(Arb.int())) { nonEmptySet ->
nonEmptySet.toNonEmptySetOrNone() shouldBe nonEmptySet.some()
}
}

"emptyList.toNonEmptySetOrNull should be null" {
@Test fun emptyListToNonEmptySetOrNullShouldBeNull() = runTest {
listOf<Int>().toNonEmptySetOrNull() shouldBe null
}

"emptyList.toNonEmptySetOrNone should be none" {
@Test fun emptyListToNonEmptySetOrNoneShouldBeNone() = runTest {
listOf<Int>().toNonEmptySetOrNone() shouldBe none()
}

"adding an element already present doesn't change the set" {
@Test fun addingAnElementAlreadyPresentDoesNotChangeTheSet() = runTest {
val element = Arb.int().next()
val initialSet: NonEmptySet<Int> = nonEmptySetOf(element) + Arb.nonEmptySet(Arb.int()).next()
initialSet.plus(element) shouldBe initialSet
}

"NonEmptySet equals Set" {
@Test fun nonEmptySetEqualsSet() = runTest {
checkAll(
Arb.nonEmptySet(Arb.int())
) { nes ->
Expand All @@ -51,7 +64,7 @@ class NonEmptySetTest : StringSpec({
}
}

"NonEmptySet equals NonEmptySet" {
@Test fun nonEmptySetEqualsNonEmptySet() = runTest {
checkAll(
Arb.nonEmptySet(Arb.int())
) { nes ->
Expand All @@ -62,5 +75,5 @@ class NonEmptySetTest : StringSpec({
}
}
}
})
}

Loading

0 comments on commit dbdb0e6

Please sign in to comment.