Skip to content

Commit

Permalink
Deprecate Validated (arrow-kt#2940)
Browse files Browse the repository at this point in the history
Co-authored-by: Francisco Diaz <francisco.d@47deg.com>
  • Loading branch information
nomisRev and franciscodr authored Mar 1, 2023
1 parent 7a7f0a9 commit 8e0121a
Show file tree
Hide file tree
Showing 4 changed files with 539 additions and 14 deletions.
4 changes: 3 additions & 1 deletion arrow-libs/core/arrow-core/api/arrow-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public abstract class arrow/core/Either {
public final fun swap ()Larrow/core/Either;
public final fun tap (Lkotlin/jvm/functions/Function1;)Larrow/core/Either;
public final fun tapLeft (Lkotlin/jvm/functions/Function1;)Larrow/core/Either;
public final fun toEither ()Larrow/core/Either;
public final fun toIor ()Larrow/core/Ior;
public fun toString ()Ljava/lang/String;
public final fun toValidated ()Larrow/core/Validated;
public final fun toValidatedNel ()Larrow/core/Validated;
Expand Down Expand Up @@ -297,6 +299,7 @@ public final class arrow/core/EitherKt {
public static final fun handleErrorWith (Larrow/core/Either;Lkotlin/jvm/functions/Function1;)Larrow/core/Either;
public static final fun left (Ljava/lang/Object;)Larrow/core/Either;
public static final fun leftIfNull (Larrow/core/Either;Lkotlin/jvm/functions/Function0;)Larrow/core/Either;
public static final fun leftNel (Ljava/lang/Object;)Larrow/core/Either;
public static final fun leftWiden (Larrow/core/Either;)Larrow/core/Either;
public static final fun merge (Larrow/core/Either;)Ljava/lang/Object;
public static final fun orNull (Larrow/core/Either;)Ljava/lang/Object;
Expand All @@ -315,7 +318,6 @@ public final class arrow/core/EitherKt {
public static final fun sequenceOption (Larrow/core/Either;)Larrow/core/Option;
public static final fun sequenceValidated (Larrow/core/Either;)Larrow/core/Validated;
public static final fun toEitherNel (Larrow/core/Either;)Larrow/core/Either;
public static final fun toEitherNel (Ljava/lang/Object;)Larrow/core/Either;
public static final fun widen (Larrow/core/Either;)Larrow/core/Either;
public static final fun zip (Larrow/core/Either;Larrow/core/Either;)Larrow/core/Either;
public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function10;)Larrow/core/Either;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -921,10 +921,10 @@ public sealed class Either<out A, out B> {

@Deprecated(
NicheAPI + "Prefer when or fold instead",
ReplaceWith("MN.run { fold({ MN.empty().combine(f(it)) }, { MN.empty().combine(g(it)) }) }")
ReplaceWith("MN.run { fold({ empty().combine(f(it)) }, { empty().combine(g(it)) }) }")
)
public inline fun <C> bifoldMap(MN: Monoid<C>, f: (A) -> C, g: (B) -> C): C =
MN.run { fold({ MN.empty().combine(f(it)) }, { MN.empty().combine(g(it)) }) }
MN.run { fold({ empty().combine(f(it)) }, { empty().combine(g(it)) }) }

/**
* Swap the generic parameters [A] and [B] of this [Either].
Expand Down Expand Up @@ -1138,6 +1138,10 @@ public sealed class Either<out A, out B> {
return getOrElse { null }
}

@Deprecated(
"orNone is being renamed to getOrNone to be more consistent with the Kotlin Standard Library naming",
ReplaceWith("getOrNone()")
)
public fun orNone(): Option<B> = getOrNone()

/**
Expand Down Expand Up @@ -1197,14 +1201,14 @@ public sealed class Either<out A, out B> {
public inline fun <C> traverseNullable(fa: (B) -> C?): Either<A, C>? =
orNull()?.let(fa)?.right()

// TODO will be renamed to mapAccumulating in 2.x.x. Backport, and deprecate in 1.x.x
@Deprecated(
NicheAPI + "Prefer using the Either DSL, or explicit fold or when",
ReplaceWith("fold({ it.left().valid() }, { fa(it).map(::Right) })")
)
@OptIn(ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
public inline fun <AA, C> traverse(fa: (B) -> Validated<AA, C>): Validated<AA, Either<A, C>> =
when (this) {
is Right -> fa(this.value).map(::Right)
is Left -> this.valid()
}
fold({ it.left().valid() }, { fa(it).map(::Right) })

@Deprecated("traverseValidated is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(fa)"))
public inline fun <AA, C> traverseValidated(fa: (B) -> Validated<AA, C>): Validated<AA, Either<A, C>> =
Expand Down Expand Up @@ -1333,6 +1337,9 @@ public sealed class Either<out A, out B> {
public fun toValidated(): Validated<A, B> =
fold({ it.invalid() }, { it.valid() })

public fun toIor(): Ior<A, B> =
fold({ Ior.Left(it) }, { Ior.Right(it) })

public companion object {

@Deprecated(
Expand Down Expand Up @@ -1944,6 +1951,13 @@ public sealed class Either<out A, out B> {
)
public fun void(): Either<A, Unit> =
map { }

@Deprecated(
"Facilitates the migration from Validated to Either, you can simply remove this method call.",
ReplaceWith("this")
)
public inline fun toEither(): Either<A, B> =
this
}

/**
Expand Down Expand Up @@ -2596,7 +2610,7 @@ public const val RedundantAPI: String =
public fun <E, A> Either<E, A>.toEitherNel(): EitherNel<E, A> =
mapLeft { nonEmptyListOf(it) }

public fun <E> E.toEitherNel(): EitherNel<E, Nothing> =
public fun <E> E.leftNel(): EitherNel<E, Nothing> =
nonEmptyListOf(this).left()

/**
Expand Down
Loading

0 comments on commit 8e0121a

Please sign in to comment.