From 4b06615ebfad407c6667e784e371aa43dd9d5b18 Mon Sep 17 00:00:00 2001
From: i-walker <46971368+i-walker@users.noreply.github.com>
Date: Tue, 3 May 2022 14:14:48 +0200
Subject: [PATCH 1/9] rename sequencex traversex for NonemptyList + cleanup
---
.../kotlin/arrow/core/NonEmptyList.kt | 57 ++++++++++++++++---
.../commonTest/kotlin/arrow/core/MapKTest.kt | 2 +-
.../kotlin/arrow/core/NonEmptyListTest.kt | 23 ++++----
.../kotlin/arrow/core/SequenceKTest.kt | 8 +--
.../fx/coroutines/ParTraverseEitherTest.kt | 5 +-
5 files changed, 68 insertions(+), 27 deletions(-)
diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt
index 26adcb8c9bc..efc7922c75d 100644
--- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt
+++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt
@@ -3,6 +3,7 @@ package arrow.core
import arrow.core.Either.Left
import arrow.core.Either.Right
import arrow.typeclasses.Semigroup
+import kotlin.experimental.ExperimentalTypeInference
import kotlin.jvm.JvmStatic
public typealias Nel = NonEmptyList
@@ -408,24 +409,49 @@ public fun NonEmptyList.unzip(f: (C) -> Pair): Pair NonEmptyList.traverseEither(f: (A) -> Either): Either> {
+@Deprecated(
+ "traverseEither is being renamed to traverse to simplify the Arrow API",
+ ReplaceWith("traverse(f)", "arrow.core.traverse")
+)
+public inline fun NonEmptyList.traverseEither(f: (A) -> Either): Either> =
+ traverse(f)
+
+@OptIn(ExperimentalTypeInference::class)
+@OverloadResolutionByLambdaReturnType
+public inline fun NonEmptyList.traverse(f: (A) -> Either): Either> {
val acc = mutableListOf()
forEach { a ->
when (val res = f(a)) {
is Right -> acc.add(res.value)
- is Left -> return@traverseEither res
+ is Left -> return@traverse res
}
}
// Safe due to traverse laws
return NonEmptyList.fromListUnsafe(acc).right()
}
+@Deprecated("sequenceEither is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence"))
public fun NonEmptyList>.sequenceEither(): Either> =
- traverseEither(::identity)
+ sequence()
+
+public fun NonEmptyList>.sequence(): Either> =
+ traverse(::identity)
+@Deprecated(
+ "traverseValidated is being renamed to traverse to simplify the Arrow API",
+ ReplaceWith("traverse(semigroup, f)", "arrow.core.traverse")
+)
public inline fun NonEmptyList.traverseValidated(
semigroup: Semigroup,
f: (A) -> Validated
+): Validated> =
+ traverse(semigroup, f)
+
+@OptIn(ExperimentalTypeInference::class)
+@OverloadResolutionByLambdaReturnType
+public inline fun NonEmptyList.traverse(
+ semigroup: Semigroup,
+ f: (A) -> Validated
): Validated> =
fold(mutableListOf().valid() as Validated>) { acc, a ->
when (val res = f(a)) {
@@ -440,20 +466,37 @@ public inline fun NonEmptyList.traverseValidated(
}
}.map { NonEmptyList.fromListUnsafe(it) }
+@Deprecated("sequenceValidated is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence"))
public fun NonEmptyList>.sequenceValidated(semigroup: Semigroup): Validated> =
- traverseValidated(semigroup, ::identity)
+ sequence(semigroup)
+
+public fun NonEmptyList>.sequence(semigroup: Semigroup): Validated> =
+ traverse(semigroup, ::identity)
-public inline fun NonEmptyList.traverseOption(f: (A) -> Option): Option> {
+@Deprecated(
+ "traverseOption is being renamed to traverse to simplify the Arrow API",
+ ReplaceWith("traverse(f)", "arrow.core.traverse")
+)
+public inline fun NonEmptyList.traverseOption(f: (A) -> Option): Option> =
+ traverse(f)
+
+@OptIn(ExperimentalTypeInference::class)
+@OverloadResolutionByLambdaReturnType
+public inline fun NonEmptyList.traverse(f: (A) -> Option): Option> {
val acc = mutableListOf()
forEach { a ->
when (val res = f(a)) {
is Some -> acc.add(res.value)
- is None -> return@traverseOption res
+ is None -> return@traverse res
}
}
// Safe due to traverse laws
return NonEmptyList.fromListUnsafe(acc).some()
}
+@Deprecated("sequenceOption is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence"))
public fun NonEmptyList