diff --git a/arrow-libs/core/arrow-continuations/src/test/kotlin/generic/SuspendingComputationTest.kt b/arrow-libs/core/arrow-continuations/src/test/kotlin/generic/SuspendingComputationTest.kt index ffd73f88cca..247c5468a9a 100644 --- a/arrow-libs/core/arrow-continuations/src/test/kotlin/generic/SuspendingComputationTest.kt +++ b/arrow-libs/core/arrow-continuations/src/test/kotlin/generic/SuspendingComputationTest.kt @@ -1,8 +1,8 @@ package generic -import arrow.core.Left -import arrow.core.Right import arrow.core.computations.either +import arrow.core.Either.Right +import arrow.core.Either.Left import io.kotlintest.fail import io.kotlintest.shouldBe import io.kotlintest.shouldThrow diff --git a/arrow-libs/core/arrow-continuations/src/test/kotlin/generic/TestSuite.kt b/arrow-libs/core/arrow-continuations/src/test/kotlin/generic/TestSuite.kt index 210ee49470c..185d43f5bf8 100644 --- a/arrow-libs/core/arrow-continuations/src/test/kotlin/generic/TestSuite.kt +++ b/arrow-libs/core/arrow-continuations/src/test/kotlin/generic/TestSuite.kt @@ -4,7 +4,7 @@ import arrow.continuations.Reset import arrow.continuations.generic.MultiShotDelimContScope import arrow.continuations.generic.RestrictedScope import arrow.core.Either -import arrow.core.Left +import arrow.core.Either.Left import arrow.core.Tuple2 import arrow.core.Tuple3 import arrow.core.test.UnitSpec diff --git a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/AndThen.kt b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/AndThen.kt index fd7da86c2b8..943b7d0342a 100644 --- a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/AndThen.kt +++ b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/AndThen.kt @@ -193,8 +193,8 @@ sealed class AndThen : (A) -> B { private tailrec fun step(a: A, t: I, fn: (A) -> AndThen>): B { val af = fn(a)(t) return when (af) { - is Either.Right -> af.b - is Either.Left -> step(af.a, t, fn) + is Either.Right -> af.value + is Either.Left -> step(af.value, t, fn) } } diff --git a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Either.kt index b9acf9a8eb3..2892b03ec61 100644 --- a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Either.kt @@ -230,12 +230,12 @@ import arrow.typeclasses.Semigroup * //sampleStart * val x = magic("2") * val value = when(x) { - * is Either.Left -> when (x.a){ + * is Either.Left -> when (x.value) { * is NumberFormatException -> "Not a number!" * is IllegalArgumentException -> "Can't take reciprocal of 0!" * else -> "Unknown error" * } - * is Either.Right -> "Got reciprocal: ${x.b}" + * is Either.Right -> "Got reciprocal: ${x.value}" * } * //sampleEnd * fun main() { @@ -302,11 +302,11 @@ import arrow.typeclasses.Semigroup * //sampleStart * val x = magic("2") * val value = when(x) { - * is Either.Left -> when (x.a){ + * is Either.Left -> when (x.value) { * is Error.NotANumber -> "Not a number!" * is Error.NoZeroReciprocal -> "Can't take reciprocal of 0!" * } - * is Either.Right -> "Got reciprocal: ${x.b}" + * is Either.Right -> "Got reciprocal: ${x.value}" * } * //sampleEnd * fun main() { @@ -451,7 +451,7 @@ import arrow.typeclasses.Semigroup * `Either` can be transformed to `Either` using the `swap()` method. * * ```kotlin:ank:playground - * import arrow.core.Right + * import arrow.core.Either.Left * import arrow.core.Either * * //sampleStart @@ -617,7 +617,7 @@ import arrow.typeclasses.Semigroup * See the examples below: * * ```kotlin:ank:playground - * import arrow.core.Right + * import arrow.core.Either.Right * import arrow.core.leftIfNull * * val value = @@ -630,7 +630,7 @@ import arrow.typeclasses.Semigroup * ``` * * ```kotlin:ank:playground - * import arrow.core.Right + * import arrow.core.Either.Right * import arrow.core.leftIfNull * * val value = @@ -643,7 +643,7 @@ import arrow.typeclasses.Semigroup * ``` * * ```kotlin:ank:playground - * import arrow.core.Left + * import arrow.core.Either.Left * import arrow.core.leftIfNull * * val value = @@ -723,7 +723,7 @@ import arrow.typeclasses.Semigroup * Transforming the inner contents * * ```kotlin:ank:playground - * import arrow.core.Right + * import arrow.core.Either.Left * * val value = * //sampleStart @@ -916,8 +916,8 @@ sealed class Either { * * Example: * ```kotlin:ank:playground - * import arrow.core.Right - * import arrow.core.Left + * import arrow.core.Either.Left + * import arrow.core.Either.Right * * //sampleStart * val right = Right(12).orNull() // Result: 12 @@ -990,7 +990,7 @@ sealed class Either { if (n <= 0) emptyList().right() else when (this) { is Left -> this - is Right -> List(n) { this.b }.right() + is Right -> List(n) { this.value }.right() } inline fun traverse(fa: (B) -> Iterable): List> = @@ -1001,7 +1001,7 @@ sealed class Either { inline fun traverseValidated(fa: (B) -> Validated): Validated> = when (this) { - is Right -> fa(this.b).map { Right(it) } + is Right -> fa(this.value).map { Right(it) } is Left -> this.valid() } @@ -1019,7 +1019,7 @@ sealed class Either { inline fun findOrNull(predicate: (B) -> Boolean): B? = when (this) { - is Right -> if (predicate(this.b)) this.b else null + is Right -> if (predicate(this.value)) this.value else null is Left -> null } @@ -1033,39 +1033,25 @@ sealed class Either { /** * The left side of the disjoint union, as opposed to the [Right] side. */ - data class Left constructor( - @Deprecated("Use value instead", ReplaceWith("value")) - val a: A - ) : Either() { - val value: A = a + data class Left constructor(val value: A) : Either() { override val isLeft = true override val isRight = false - override fun toString(): String = "Either.Left($a)" + override fun toString(): String = "Either.Left($value)" - companion object { - @Deprecated("Deprecated, use the constructor instead", ReplaceWith("Either.Left(a)", "arrow.core.Either")) - operator fun invoke(a: A): Either = Left(a) - } + companion object } /** * The right side of the disjoint union, as opposed to the [Left] side. */ - data class Right constructor( - @Deprecated("Use value instead", ReplaceWith("value")) - val b: B - ) : Either() { - val value: B = b + data class Right constructor(val value: B) : Either() { override val isLeft = false override val isRight = true - override fun toString(): String = "Either.Right($b)" + override fun toString(): String = "Either.Right($value)" - companion object { - @Deprecated("Deprecated, use the constructor instead", ReplaceWith("Either.Right(b)", "arrow.core.Either")) - operator fun invoke(b: B): Either = Right(b) - } + companion object } override fun toString(): String = fold( @@ -1081,34 +1067,22 @@ sealed class Either { companion object { - @Deprecated( - "This constructor is duplicated with Either.Left. Use Either.Left instead.", - ReplaceWith("Either.Left(left)", "arrow.core.Either") - ) - fun left(left: L): Either = Left(left) - - @Deprecated( - "This constructor is duplicated with Either.Right. Use Either.Right instead.", - ReplaceWith("Either.Right(right)", "arrow.core.Either") - ) - fun right(right: R): Either = Right(right) - @PublishedApi internal val leftUnit: Either = - left(Unit) + Left(Unit) @PublishedApi - internal val unit: Either = right(Unit) + internal val unit: Either = Right(Unit) fun fromNullable(a: A?): Either = a?.right() ?: Unit.left() tailrec fun tailRecM(a: A, f: (A) -> Either>): Either { return when (val ev = f(a)) { - is Left -> Left(ev.a) + is Left -> Left(ev.value) is Right -> { - when (val b = ev.b) { - is Left -> tailRecM(b.a, f) - is Right -> Right(b.b) + when (val b = ev.value) { + is Left -> tailRecM(b.value, f) + is Right -> Right(b.value) } } } @@ -1137,7 +1111,7 @@ sealed class Either { * @return [Either.Right] if evaluation succeed, [Either.Left] otherwise */ inline fun conditionally(test: Boolean, ifFalse: () -> L, ifTrue: () -> R): Either = - if (test) right(ifTrue()) else left(ifFalse()) + if (test) Right(ifTrue()) else Left(ifFalse()) @Deprecated("Use the inline version. Hidden for binary compat", level = DeprecationLevel.HIDDEN) suspend inline fun catch(f: suspend () -> R): Either = @@ -1375,10 +1349,6 @@ sealed class Either { mapConst(Unit) } -fun Left(left: L): Either = Left(left) - -fun Right(right: R): Either = Right(right) - fun Semigroup.Companion.either(SA: Semigroup, SB: Semigroup): Semigroup> = EitherSemigroup(SA, SB) @@ -1472,6 +1442,7 @@ inline fun Either.filterOrElse(predicate: (B) -> Boolean, default: * {: data-executable='true'} * ```kotlin:ank * import arrow.core.* + * import arrow.core.Either.Right * * Right(12).filterOrOther({ it > 10 }, { -1 }) * ``` @@ -1483,6 +1454,8 @@ inline fun Either.filterOrElse(predicate: (B) -> Boolean, default: * * {: data-executable='true'} * ```kotlin:ank + * import arrow.core.Either.Left + * * val left: Either = Left(12) * left.filterOrOther({ it > 10 }, { -1 }) * ``` @@ -1587,19 +1560,19 @@ inline fun Any?.rightIfNull(default: () -> A): Either = when (t */ inline fun Either.handleErrorWith(f: (A) -> Either): Either = when (this) { - is Left -> f(this.a) + is Left -> f(this.value) is Right -> this } inline fun Either.handleError(f: (A) -> B): Either = when (this) { - is Left -> f(a).right() + is Left -> f(value).right() is Right -> this } inline fun Either.redeem(fe: (A) -> C, fa: (B) -> C): Either = when (this) { - is Left -> fe(a).right() + is Left -> fe(value).right() is Right -> map(fa) } @@ -1612,12 +1585,12 @@ operator fun , B : Comparable> Either.compareTo(other fun Either.combine(SGA: Semigroup, SGB: Semigroup, b: Either): Either = when (this) { is Left -> when (b) { - is Left -> Left(SGA.run { a.combine(b.a) }) + is Left -> Left(SGA.run { value.combine(b.value) }) is Right -> this } is Right -> when (b) { is Left -> b - is Right -> Either.right(SGB.run { this@combine.b.combine(b.b) }) + is Right -> Either.Right(SGB.run { this@combine.value.combine(b.value) }) } } @@ -1666,7 +1639,7 @@ fun Either.replicate(n: Int, MB: Monoid): Either = else MB.run { when (this@replicate) { is Left -> this@replicate - is Right -> List(n) { this@replicate.b }.combineAll().right() + is Right -> List(n) { this@replicate.value }.combineAll().right() } } @@ -1683,14 +1656,14 @@ fun Either>.selectM(f: Either C>): Either Either.ensure(error: () -> A, predicate: (B) -> Boolean): Either = when (this) { - is Right -> if (predicate(this.b)) this else error().left() + is Right -> if (predicate(this.value)) this else error().left() is Left -> this } inline fun Either.redeemWith(fa: (A) -> Either, fb: (B) -> Either): Either = when (this) { - is Left -> fa(this.a) - is Right -> fb(this.b) + is Left -> fa(this.value) + is Right -> fb(this.value) } fun Either>.sequence(): List> = diff --git a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Eval.kt b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Eval.kt index 58d26e3cf59..4d5be634995 100644 --- a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Eval.kt +++ b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Eval.kt @@ -62,8 +62,8 @@ sealed class Eval { fun tailRecM(a: A, f: (A) -> Eval>): Eval = f(a).flatMap { eval: Either -> when (eval) { - is Either.Left -> tailRecM(eval.a, f) - is Either.Right -> just(eval.b) + is Either.Left -> tailRecM(eval.value, f) + is Either.Right -> just(eval.value) } } @@ -144,35 +144,8 @@ sealed class Eval { fun raise(t: Throwable): Eval = defer { throw t } - @Deprecated( - "This constructor is deprecated in favor of the Now constructor", - ReplaceWith("Eval.now(kotlin.Unit)", "arrow.core.Eval") - ) - val Unit: Eval = Now(kotlin.Unit) - - @Deprecated( - "This constructor is deprecated in favor of the Now constructor", - ReplaceWith("Eval.now(true)", "arrow.core.Eval") - ) - val True: Eval = Now(true) - - @Deprecated( - "This constructor is deprecated in favor of the Now constructor", - ReplaceWith("Eval.now(false)", "arrow.core.Eval") - ) - val False: Eval = Now(false) - - @Deprecated( - "This constructor is deprecated in favor of the Now constructor", - ReplaceWith("Eval.now(0)", "arrow.core.Eval") - ) - val Zero: Eval = Now(0) - - @Deprecated( - "This constructor is deprecated in favor of the Now constructor", - ReplaceWith("Eval.now(1)", "arrow.core.Eval") - ) - val One: Eval = Now(1) + @PublishedApi + internal val unit: Eval = Now(Unit) /** * Collapse the call stack for eager evaluations. @@ -265,7 +238,7 @@ sealed class Eval { b: Eval, map: (A, B) -> C ): Eval = - mapN(a, b, Unit, Unit, Unit, Unit, Unit, Unit, Unit) { aa, bb, _, _, _, _, _, _, _ -> map(aa, bb) } + mapN(a, b, unit, unit, unit, unit, unit, unit, unit) { aa, bb, _, _, _, _, _, _, _ -> map(aa, bb) } fun mapN( a: Eval, @@ -273,7 +246,7 @@ sealed class Eval { c: Eval, map: (A, B, C) -> D ): Eval = - mapN(a, b, c, Unit, Unit, Unit, Unit, Unit, Unit, Unit) { aa, bb, cc, _, _, _, _, _, _, _ -> map(aa, bb, cc) } + mapN(a, b, c, unit, unit, unit, unit, unit, unit, unit) { aa, bb, cc, _, _, _, _, _, _, _ -> map(aa, bb, cc) } fun mapN( a: Eval, @@ -282,7 +255,7 @@ sealed class Eval { d: Eval, map: (A, B, C, D) -> E ): Eval = - mapN(a, b, c, d, Unit, Unit, Unit, Unit, Unit, Unit) { aa, bb, cc, dd, _, _, _, _, _, _ -> map(aa, bb, cc, dd) } + mapN(a, b, c, d, unit, unit, unit, unit, unit, unit) { aa, bb, cc, dd, _, _, _, _, _, _ -> map(aa, bb, cc, dd) } fun mapN( a: Eval, @@ -292,7 +265,7 @@ sealed class Eval { e: Eval, map: (A, B, C, D, E) -> F ): Eval = - mapN(a, b, c, d, e, Unit, Unit, Unit, Unit, Unit) { aa, bb, cc, dd, ee, _, _, _, _, _ -> map(aa, bb, cc, dd, ee) } + mapN(a, b, c, d, e, unit, unit, unit, unit, unit) { aa, bb, cc, dd, ee, _, _, _, _, _ -> map(aa, bb, cc, dd, ee) } fun mapN( a: Eval, @@ -303,7 +276,7 @@ sealed class Eval { f: Eval, map: (A, B, C, D, E, F) -> G ): Eval = - mapN(a, b, c, d, e, f, Unit, Unit, Unit, Unit) { aa, bb, cc, dd, ee, ff, _, _, _, _ -> map(aa, bb, cc, dd, ee, ff) } + mapN(a, b, c, d, e, f, unit, unit, unit, unit) { aa, bb, cc, dd, ee, ff, _, _, _, _ -> map(aa, bb, cc, dd, ee, ff) } fun mapN( a: Eval, @@ -315,7 +288,7 @@ sealed class Eval { g: Eval, map: (A, B, C, D, E, F, G) -> H ): Eval = - mapN(a, b, c, d, e, f, g, Unit, Unit, Unit) { aa, bb, cc, dd, ee, ff, gg, _, _, _ -> map(aa, bb, cc, dd, ee, ff, gg) } + mapN(a, b, c, d, e, f, g, unit, unit, unit) { aa, bb, cc, dd, ee, ff, gg, _, _, _ -> map(aa, bb, cc, dd, ee, ff, gg) } fun mapN( a: Eval, @@ -328,7 +301,7 @@ sealed class Eval { h: Eval, map: (A, B, C, D, E, F, G, H) -> I ): Eval = - mapN(a, b, c, d, e, f, g, h, Unit, Unit) { aa, bb, cc, dd, ee, ff, gg, hh, _, _ -> map(aa, bb, cc, dd, ee, ff, gg, hh) } + mapN(a, b, c, d, e, f, g, h, unit, unit) { aa, bb, cc, dd, ee, ff, gg, hh, _, _ -> map(aa, bb, cc, dd, ee, ff, gg, hh) } fun mapN( a: Eval, @@ -342,7 +315,7 @@ sealed class Eval { i: Eval, map: (A, B, C, D, E, F, G, H, I) -> J ): Eval = - mapN(a, b, c, d, e, f, g, h, i, Unit) { aa, bb, cc, dd, ee, ff, gg, hh, ii, _ -> map(aa, bb, cc, dd, ee, ff, gg, hh, ii) } + mapN(a, b, c, d, e, f, g, h, i, unit) { aa, bb, cc, dd, ee, ff, gg, hh, ii, _ -> map(aa, bb, cc, dd, ee, ff, gg, hh, ii) } fun mapN( a: Eval, diff --git a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Ior.kt b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Ior.kt index 772ec528478..dca916ae224 100644 --- a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Ior.kt +++ b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Ior.kt @@ -75,11 +75,11 @@ sealed class Ior { @Deprecated("Deprecated, use `fromNullables` instead", ReplaceWith("fromNullables(a, b)")) fun fromOptions(oa: Option, ob: Option): Option> = when (oa) { is Some -> when (ob) { - is Some -> Some(Both(oa.t, ob.t)) - is None -> Some>(Left(oa.t)) + is Some -> Some(Both(oa.value, ob.value)) + is None -> Some>(Left(oa.value)) } is None -> when (ob) { - is Some -> Some(Right(ob.t)) + is Some -> Some(Right(ob.value)) is None -> None } } @@ -108,13 +108,13 @@ sealed class Ior { private tailrec fun Semigroup.loop(v: Ior>, f: (A) -> Ior>): Ior = when (v) { is Left -> Left(v.value) is Right -> when (v.value) { - is Either.Right -> Right(v.value.b) - is Either.Left -> loop(f(v.value.a), f) + is Either.Right -> Right(v.value.value) + is Either.Left -> loop(f(v.value.value), f) } is Both -> when (v.rightValue) { - is Either.Right -> Both(v.leftValue, v.rightValue.b) + is Either.Right -> Both(v.leftValue, v.rightValue.value) is Either.Left -> { - when (val fnb = f(v.rightValue.a)) { + when (val fnb = f(v.rightValue.value)) { is Left -> Left(v.leftValue.combine(fnb.value)) is Right -> loop(Both(v.leftValue, fnb.value), f) is Both -> loop(Both(v.leftValue.combine(fnb.leftValue), fnb.rightValue), f) @@ -126,9 +126,9 @@ sealed class Ior { fun tailRecM(a: A, f: (A) -> Ior>, SL: Semigroup): Ior = SL.run { loop(f(a), f) } - fun leftNel(a: A): IorNel = Left(NonEmptyList.of(a)) + fun leftNel(a: A): IorNel = Left(nonEmptyListOf(a)) - fun bothNel(a: A, b: B): IorNel = Both(NonEmptyList.of(a), b) + fun bothNel(a: A, b: B): IorNel = Both(nonEmptyListOf(a), b) /** * Lifts a function `(B) -> C` to the [Ior] structure returning a polymorphic function @@ -527,7 +527,7 @@ sealed class Ior { */ @Deprecated("Deprecated, use `leftOrNull` instead", ReplaceWith("leftOrNull()")) fun toLeftOption(): Option = - fold({ Option.just(it) }, { Option.empty() }, { a, _ -> Option.just(a) }) + fold({ Some(it) }, { None }, { a, _ -> Some(a) }) /** * Returns the [Left] value or `A` if this is [Left] or [Both] @@ -574,10 +574,7 @@ sealed class Ior { override fun toString(): String = "Ior.Left($value)" - companion object { - @Deprecated("Deprecated, use the constructor instead", ReplaceWith("Ior.Left(a)", "arrow.core.Ior")) - operator fun invoke(a: A): Ior = Left(a) - } + companion object } data class Right(val value: B) : Ior() { @@ -587,10 +584,7 @@ sealed class Ior { override fun toString(): String = "Ior.Right($value)" - companion object { - @Deprecated("Deprecated, use the constructor instead", ReplaceWith("Ior.Right(a)", "arrow.core.Right")) - operator fun invoke(b: B): Ior = Right(b) - } + companion object } data class Both(val leftValue: A, val rightValue: B) : Ior() { @@ -764,7 +758,7 @@ sealed class Ior { inline fun traverseEither(fa: (B) -> Either): Either> = fold( - { a -> Either.right(Left(a)) }, + { a -> Either.Right(Left(a)) }, { b -> fa(b).map { Right(it) } }, { a, b -> fa(b).map { Both(a, it) } } ) @@ -780,7 +774,7 @@ sealed class Ior { fold({ emptyList() }, { fa(it).void() }, { _, b -> fa(b).void() }) inline fun traverseEither_(fa: (B) -> Either): Either = - fold({ Either.right(Unit) }, { fa(it).void() }, { _, b -> fa(b).void() }) + fold({ Either.Right(Unit) }, { fa(it).void() }, { _, b -> fa(b).void() }) inline fun traverseValidated_(fa: (B) -> Validated): Validated = fold({ Valid(Unit) }, { fa(it).void() }, { _, b -> fa(b).void() }) diff --git a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Iterable.kt b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Iterable.kt index 3c2c34d4b1d..f0589e8d5da 100644 --- a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Iterable.kt +++ b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Iterable.kt @@ -274,10 +274,10 @@ private tailrec fun go( if (v.isNotEmpty()) { when (val head: Either = v.first()) { is Either.Right -> { - buf += head.b + buf += head.value go(buf, f, v.drop(1)) } - is Either.Left -> go(buf, f, (f(head.a) + v.drop(1))) + is Either.Left -> go(buf, f, (f(head.value) + v.drop(1))) } } } diff --git a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/ListK.kt b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/ListK.kt index 909fbcd29c9..cc6f7dbf742 100644 --- a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/ListK.kt +++ b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/ListK.kt @@ -51,8 +51,8 @@ const val ListKDeprecation = * Traversing a list creates a new container [Kind]({{'/patterns/glossary/#type-constructors' | relative_url }}) by combining the result of a function applied to each element: * * ```kotlin:ank:playground - * import arrow.core.Right - * import arrow.core.Left + * import arrow.core.Either.Left + * import arrow.core.Either.Right * import arrow.core.traverseEither * * //sampleStart @@ -67,7 +67,7 @@ const val ListKDeprecation = * and complements the convenient function `sequence()` that converts a list of `ListK>` into a `Kind>`: * * ```kotlin:ank:playground - * import arrow.core.Right + * import arrow.core.Either.Left * import arrow.core.sequenceEither * * //sampleStart @@ -183,8 +183,8 @@ data class ListK(private val list: List) : List by list { ): ListK, Option>> = alignWith(this, other) { ior -> ior.fold( - { it.some() toT Option.empty() }, - { Option.empty() toT it.some() }, + { it.some() toT None }, + { None toT it.some() }, { a, b -> a.some() toT b.some() } ) } @@ -425,10 +425,10 @@ data class ListK(private val list: List) : List by list { val head: Either = v.first() when (head) { is Either.Right -> { - buf += head.b + buf += head.value go(buf, f, v.drop(1).k()) } - is Either.Left -> go(buf, f, (f(head.a) + v.drop(1)).k()) + is Either.Left -> go(buf, f, (f(head.value) + v.drop(1)).k()) } } } diff --git a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/MapK.kt b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/MapK.kt index f1d2921417d..39c70286d9d 100644 --- a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/MapK.kt +++ b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/MapK.kt @@ -182,7 +182,7 @@ fun Map.k(): MapK = MapK(this) @Deprecated("Deprecated, use nullable instead", ReplaceWith("Tuple2>?.let { ... }")) fun Option>.k(): MapK = when (this) { - is Some -> mapOf(this.t).k() + is Some -> mapOf(this.value).k() is None -> emptyMap().k() } diff --git a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/NonEmptyList.kt b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/NonEmptyList.kt index 43075bd8ba2..1d49fded729 100644 --- a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/NonEmptyList.kt +++ b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/NonEmptyList.kt @@ -228,40 +228,15 @@ class NonEmptyList( companion object { - @Deprecated( - "Renamed to nonEmptyListOf to align with Kotlin Std standards", - ReplaceWith("nonEmptyListOf(head, t)", "arrow.core.nonEmptyListOf") - ) - operator fun invoke(head: A, vararg t: A): NonEmptyList = - NonEmptyList(head, t.asList()) - - @Deprecated( - "Renamed to nonEmptyListOf to align with Kotlin Std standards", - ReplaceWith("nonEmptyListOf(head, t)", "arrow.core.nonEmptyListOf") - ) - fun of(head: A, vararg t: A): NonEmptyList = - NonEmptyList(head, t.asList()) - fun fromList(l: List): Option> = if (l.isEmpty()) None else Some(NonEmptyList(l)) fun fromListUnsafe(l: List): NonEmptyList = NonEmptyList(l) - @Deprecated( - "just is deprecated, and will be removed in 0.13.0. Please use nonEmptyListOf instead.", - ReplaceWith( - "nonEmptyListOf(a)", - "arrow.core.NonEmptyList" - ), - DeprecationLevel.WARNING - ) - fun just(a: A): NonEmptyList = - of(a) - @PublishedApi internal val unit: NonEmptyList = - of(Unit) + nonEmptyListOf(Unit) inline fun mapN( b: NonEmptyList, @@ -394,14 +369,14 @@ class NonEmptyList( val head: Either = v.head when (head) { is Either.Right -> { - buf += head.b + buf += head.value val x = fromList(v.tail) when (x) { - is Some>> -> go(buf, f, x.t) + is Some>> -> go(buf, f, x.value) is None -> Unit } } - is Either.Left -> go(buf, f, f(head.a) + v.tail) + is Either.Left -> go(buf, f, f(head.value) + v.tail) } } @@ -419,18 +394,6 @@ fun nonEmptyListOf(head: A, vararg t: A): NonEmptyList = inline fun A.nel(): NonEmptyList = nonEmptyListOf(this) -@Deprecated( - "Kind is deprecated, and will be removed in 0.13.0. Please the plus method defined for NonEmptyList instead", - ReplaceWith( - "fix().plus(y.fix())", - "arrow.core.fix", - "arrow.core.plus" - ), - DeprecationLevel.WARNING -) -fun NonEmptyList.combineK(y: NonEmptyList): NonEmptyList = - this.plus(y) - operator fun > NonEmptyList.compareTo(other: NonEmptyList): Int = all.compareTo(other.all) @@ -438,7 +401,7 @@ fun NonEmptyList>.flatten(): NonEmptyList = this.flatMap(::identity) fun NonEmptyList>.selectM(f: NonEmptyList<(A) -> B>): NonEmptyList = - this.flatMap { it.fold({ a -> f.map { ff -> ff(a) } }, { b -> NonEmptyList.just(b) }) } + this.flatMap { it.fold({ a -> f.map { ff -> ff(a) } }, { b -> nonEmptyListOf(b) }) } fun NonEmptyList>.unzip(): Pair, NonEmptyList> = this.unzip(::identity) @@ -452,8 +415,8 @@ fun NonEmptyList.unzip(f: (C) -> Pair): Pair, } inline fun NonEmptyList.traverseEither(f: (A) -> Either): Either> = - foldRight(f(head).map { NonEmptyList.just(it) }) { a, acc -> - f(a).ap(acc.map { bs -> { b: B -> NonEmptyList(b) + bs } }) + foldRight(f(head).map { nonEmptyListOf(it) }) { a, acc -> + f(a).ap(acc.map { bs -> { b: B -> nonEmptyListOf(b) + bs } }) } inline fun NonEmptyList.flatTraverseEither(f: (A) -> Either>): Either> = @@ -478,8 +441,8 @@ fun NonEmptyList>.sequenceEither_(): Either = traverseEither_(::identity) inline fun NonEmptyList.traverseValidated(semigroup: Semigroup, f: (A) -> Validated): Validated> = - foldRight(f(head).map { NonEmptyList(it) }) { a, acc -> - f(a).ap(semigroup, acc.map { bs -> { b: B -> NonEmptyList(b) + bs } }) + foldRight(f(head).map { nonEmptyListOf(it) }) { a, acc -> + f(a).ap(semigroup, acc.map { bs -> { b: B -> nonEmptyListOf(b) + bs } }) } inline fun NonEmptyList.flatTraverseValidated(semigroup: Semigroup, f: (A) -> Validated>): Validated> = diff --git a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Option.kt b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Option.kt index e96ca7d6c40..b6afa6f41b1 100644 --- a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Option.kt +++ b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Option.kt @@ -125,7 +125,7 @@ import arrow.typeclasses.Semigroup * //sampleStart * val someValue: Option = Some(20.0) * val value = when(someValue) { - * is Some -> someValue.t + * is Some -> someValue.value * is None -> 0.0 * } * //sampleEnd @@ -142,7 +142,7 @@ import arrow.typeclasses.Semigroup * //sampleStart * val noValue: Option = None * val value = when(noValue) { - * is Some -> noValue.t + * is Some -> noValue.value * is None -> 0.0 * } * //sampleEnd @@ -329,38 +329,12 @@ sealed class Option { companion object { - /** - * Lifts a pure [A] value to [Option] - * - * {: data-executable='true'} - * - * ```kotlin:ank - * import arrow.core.Option - * fun main(args: Array) { - * //sampleStart - * val result: Option = Option.just(1) - * //sampleEnd - * println(result) - * } - * ``` - * - */ - @Deprecated( - "just is deprecated, and will be removed in 0.13.0. Please use Some instead.", - ReplaceWith( - "Some(a)", - "arrow.core.Some" - ), - DeprecationLevel.WARNING - ) - fun just(a: A): Option = Some(a) - tailrec fun tailRecM(a: A, f: (A) -> Option>): Option = when (val option = f(a)) { is Some -> { - when (option.t) { - is Either.Left -> tailRecM(option.t.a, f) - is Either.Right -> Some(option.t.b) + when (option.value) { + is Either.Left -> tailRecM(option.value.value, f) + is Either.Right -> Some(option.value.value) } } is None -> None @@ -378,16 +352,6 @@ sealed class Option { None } - @Deprecated( - "empty is deprecated, and will be removed in 0.13.0. Please use None instead.", - ReplaceWith( - "None", - "arrow.core.None" - ), - DeprecationLevel.WARNING - ) - fun empty(): Option = None - @PublishedApi internal val unit: Option = Some(Unit) @@ -489,7 +453,7 @@ sealed class Option { map: (A, B, C, D, E, F, G, H, I, J) -> K ): Option = if (a is Some && b is Some && c is Some && d is Some && e is Some && f is Some && g is Some && h is Some && i is Some && j is Some) { - Some(map(a.t, b.t, c.t, d.t, e.t, f.t, g.t, h.t, i.t, j.t)) + Some(map(a.value, b.value, c.value, d.value, e.value, f.value, g.value, h.value, i.value, j.value)) } else { None } @@ -573,7 +537,7 @@ sealed class Option { inline fun fold(ifEmpty: () -> R, ifSome: (A) -> R): R = when (this) { is None -> ifEmpty() - is Some -> ifSome(t) + is Some -> ifSome(value) } /** @@ -601,7 +565,7 @@ sealed class Option { inline fun flatMap(f: (A) -> Option): Option = when (this) { is None -> this - is Some -> f(t) + is Some -> f(value) } fun align(b: Option): Option> = @@ -627,20 +591,20 @@ sealed class Option { inline fun crosswalk(f: (A) -> Option): Option> = when (this) { - is None -> empty().map { empty() } - is Some -> f(t).map { Some(it) } + is None -> this + is Some -> f(value).map { Some(it) } } inline fun crosswalkMap(f: (A) -> Map): Map> = when (this) { is None -> emptyMap() - is Some -> f(t).mapValues { Some(it.value) } + is Some -> f(value).mapValues { Some(it.value) } } inline fun crosswalkNull(f: (A) -> B?): Option? = when (this) { is None -> null - is Some -> f(t)?.let { Some(it) } + is Some -> f(value)?.let { Some(it) } } /** @@ -719,7 +683,7 @@ sealed class Option { */ inline fun findOrNull(predicate: (A) -> Boolean): A? = when (this) { - is Some -> if (predicate(t)) t else null + is Some -> if (predicate(value)) value else null is None -> null } @@ -731,13 +695,13 @@ sealed class Option { inline fun flatTraverseEither(f: (A) -> Either>): Either> = fold( - { Right(empty()) }, + { Right(None) }, { f(it) } ) inline fun flatTraverseValidated(f: (A) -> Validated>): Validated> = fold( - { Valid(empty()) }, + { Valid(None) }, { f(it) } ) @@ -747,13 +711,13 @@ sealed class Option { inline fun foldLeft(initial: B, operation: (B, A) -> B): B = when (this) { - is Some -> operation(initial, t) + is Some -> operation(initial, value) is None -> initial } inline fun foldRight(initial: Eval, crossinline operation: (A, Eval) -> Eval): Eval = when (this) { - is Some -> Eval.defer { operation(t, initial) } + is Some -> Eval.defer { operation(value, initial) } is None -> initial } @@ -799,7 +763,7 @@ sealed class Option { inline fun reduceOrNull(initial: (A) -> B, operation: (acc: B, A) -> B): B? = when (this) { is None -> null - is Some -> operation(initial(t), t) + is Some -> operation(initial(value), value) } inline fun reduceRightEvalOrNull( @@ -808,7 +772,7 @@ sealed class Option { ): Eval = when (this) { is None -> Eval.now(null) - is Some -> operation(t, Eval.now(initial(t))) + is Some -> operation(value, Eval.now(initial(value))) } fun replicate(n: Int): Option> = @@ -822,7 +786,7 @@ sealed class Option { inline fun traverseEither(fa: (A) -> Either): Either> = when (this) { - is Some -> fa(t).map { Some(it) } + is Some -> fa(value).map { Some(it) } is None -> Right(this) } @@ -831,7 +795,7 @@ sealed class Option { inline fun traverseValidated(fa: (A) -> Validated): Validated> = when (this) { - is Some -> fa(t).map { Some(it) } + is Some -> fa(value).map { Some(it) } is None -> Valid(this) } @@ -842,10 +806,10 @@ sealed class Option { this.fold({ emptyList() }, { f(it).toList() }) inline fun traverseFilterEither(f: (A) -> Either>): Either> = - this.fold({ Right(empty()) }, f) + this.fold({ Right(None) }, f) inline fun traverseFilterValidated(f: (A) -> Validated>): Validated> = - this.fold({ Valid(empty()) }, f) + this.fold({ Valid(None) }, f) inline fun toEither(ifEmpty: () -> L): Either = fold({ ifEmpty().left() }, { it.right() }) @@ -922,14 +886,10 @@ object None : Option() { override fun toString(): String = "Option.None" } -data class Some( - @Deprecated("Use value instead", ReplaceWith("value")) - val t: T -) : Option() { - val value: T = t +data class Some(val value: T) : Option() { override fun isEmpty() = false - override fun toString(): String = "Option.Some($t)" + override fun toString(): String = "Option.Some($value)" } /** @@ -998,7 +958,7 @@ fun Option>.branch(fa: Option<(A) -> C>, fb: Option<(B) - } private fun Option.selector(): Option> = - map { bool -> if (bool) Either.right(Unit) else Either.left(Unit) } + map { bool -> if (bool) Either.unit else Either.leftUnit } fun Option.whenS(x: Option<() -> Unit>): Option = selector().select(x.map { f -> { _: Unit -> f() } }) @@ -1019,7 +979,7 @@ fun Option.combineAll(MA: Monoid): A = MA.run { inline fun Option.ensure(error: () -> Unit, predicate: (A) -> Boolean): Option = when (this) { is Some -> - if (predicate(t)) this + if (predicate(value)) this else { error() None @@ -1138,7 +1098,7 @@ fun Option>.unalign(): Pair, Option> = inline fun Option.unalign(f: (C) -> Ior): Pair, Option> = when (val option = this.map(f)) { is None -> None to None - is Some -> when (val v = option.t) { + is Some -> when (val v = option.value) { is Ior.Left -> Some(v.value) to None is Ior.Right -> None to Some(v.value) is Ior.Both -> Some(v.leftValue) to Some(v.rightValue) @@ -1165,7 +1125,7 @@ fun Option>.unzip(): Pair, Option> = inline fun Option.unzip(f: (C) -> Pair): Pair, Option> = fold( - { Option.empty() to Option.empty() }, + { None to None }, { f(it).let { pair -> Some(pair.first) to Some(pair.second) }} ) @@ -1194,7 +1154,7 @@ fun Option.widen(): Option = fun Option.combine(SGA: Semigroup, b: Option): Option = when (this) { is Some -> when (b) { - is Some -> Some(SGA.run { t.combine(b.t) }) + is Some -> Some(SGA.run { value.combine(b.value) }) None -> this } None -> b diff --git a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/SequenceK.kt b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/SequenceK.kt index 032b62613d1..e95690fba62 100644 --- a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/SequenceK.kt +++ b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/SequenceK.kt @@ -205,14 +205,14 @@ data class SequenceK(val sequence: Sequence) : Sequence by sequence val head: Either = v.first() when (head) { is Either.Right -> { - buf += head.b + buf += head.value go(buf, f, v.drop(1).k()) } is Either.Left -> { if (v.count() == 1) { - go(buf, f, (f(head.a)).k()) + go(buf, f, (f(head.value)).k()) } else { - go(buf, f, (f(head.a) + v.drop(1)).k()) + go(buf, f, (f(head.value) + v.drop(1)).k()) } } } diff --git a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Validated.kt b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Validated.kt index 9de782e627c..3dbcb6f4e42 100644 --- a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Validated.kt +++ b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Validated.kt @@ -2,6 +2,8 @@ package arrow.core import arrow.typeclasses.Monoid import arrow.typeclasses.Semigroup +import arrow.core.Either.Left +import arrow.core.Either.Right typealias ValidatedNel = Validated, A> typealias Valid = Validated.Valid @@ -20,7 +22,7 @@ typealias Invalid = Validated.Invalid * * ```kotlin:ank * import arrow.core.Either - * import arrow.core.Left + * import arrow.core.Either.Left * import arrow.core.flatMap * * //sampleStart @@ -159,7 +161,7 @@ typealias Invalid = Validated.Invalid * //sampleStart * fun parallelValidate(v1: Validated, v2: Validated, f: (A, B) -> C): Validated { * return when { - * v1 is Validated.Valid && v2 is Validated.Valid -> Validated.Valid(f(v1.a, v2.a)) + * v1 is Validated.Valid && v2 is Validated.Valid -> Validated.Valid(f(v1.value, v2.value)) * v1 is Validated.Valid && v2 is Validated.Invalid -> v2 * v1 is Validated.Invalid && v2 is Validated.Valid -> v1 * v1 is Validated.Invalid && v2 is Validated.Invalid -> TODO() @@ -187,10 +189,10 @@ typealias Invalid = Validated.Invalid * fun parallelValidate * (v1: Validated, v2: Validated, f: (A, B) -> C): Validated, C> = * when { - * v1 is Validated.Valid && v2 is Validated.Valid -> Validated.Valid(f(v1.a, v2.a)) + * v1 is Validated.Valid && v2 is Validated.Valid -> Validated.Valid(f(v1.value, v2.value)) * v1 is Validated.Valid && v2 is Validated.Invalid -> v2.toValidatedNel() * v1 is Validated.Invalid && v2 is Validated.Valid -> v1.toValidatedNel() - * v1 is Validated.Invalid && v2 is Validated.Invalid -> Validated.Invalid(NonEmptyList(v1.e, listOf(v2.e))) + * v1 is Validated.Invalid && v2 is Validated.Invalid -> Validated.Invalid(NonEmptyList(v1.value, listOf(v2.value))) * else -> throw IllegalStateException("Not possible value") * } * //sampleEnd @@ -647,19 +649,19 @@ sealed class Validated { f: (A, B, C, D, EE, F, G, H, I, J) -> Z ): Validated = if (a is Valid && b is Valid && c is Valid && d is Valid && e is Valid && ff is Valid && g is Valid && h is Valid && i is Valid && j is Valid) { - Valid(f(a.a, b.a, c.a, d.a, e.a, ff.a, g.a, h.a, i.a, j.a)) + Valid(f(a.value, b.value, c.value, d.value, e.value, ff.value, g.value, h.value, i.value, j.value)) } else SE.run { var accumulatedError: E? = null - accumulatedError = if (a is Invalid) a.e.maybeCombine(accumulatedError) else accumulatedError - accumulatedError = if (b is Invalid) accumulatedError?.let { it.combine(b.e) } ?: b.e else accumulatedError - accumulatedError = if (c is Invalid) accumulatedError?.let { it.combine(c.e) } ?: c.e else accumulatedError - accumulatedError = if (d is Invalid) accumulatedError?.let { it.combine(d.e) } ?: d.e else accumulatedError - accumulatedError = if (e is Invalid) accumulatedError?.let { it.combine(e.e) } ?: e.e else accumulatedError - accumulatedError = if (ff is Invalid) accumulatedError?.let { it.combine(ff.e) } ?: ff.e else accumulatedError - accumulatedError = if (g is Invalid) accumulatedError?.let { it.combine(g.e) } ?: g.e else accumulatedError - accumulatedError = if (h is Invalid) accumulatedError?.let { it.combine(h.e) } ?: h.e else accumulatedError - accumulatedError = if (i is Invalid) accumulatedError?.let { it.combine(i.e) } ?: i.e else accumulatedError - accumulatedError = if (j is Invalid) accumulatedError?.let { it.combine(j.e) } ?: j.e else accumulatedError + accumulatedError = if (a is Invalid) a.value.maybeCombine(accumulatedError) else accumulatedError + accumulatedError = if (b is Invalid) accumulatedError?.let { it.combine(b.value) } ?: b.value else accumulatedError + accumulatedError = if (c is Invalid) accumulatedError?.let { it.combine(c.value) } ?: c.value else accumulatedError + accumulatedError = if (d is Invalid) accumulatedError?.let { it.combine(d.value) } ?: d.value else accumulatedError + accumulatedError = if (e is Invalid) accumulatedError?.let { it.combine(e.value) } ?: e.value else accumulatedError + accumulatedError = if (ff is Invalid) accumulatedError?.let { it.combine(ff.value) } ?: ff.value else accumulatedError + accumulatedError = if (g is Invalid) accumulatedError?.let { it.combine(g.value) } ?: g.value else accumulatedError + accumulatedError = if (h is Invalid) accumulatedError?.let { it.combine(h.value) } ?: h.value else accumulatedError + accumulatedError = if (i is Invalid) accumulatedError?.let { it.combine(i.value) } ?: i.value else accumulatedError + accumulatedError = if (j is Invalid) accumulatedError?.let { it.combine(j.value) } ?: j.value else accumulatedError Invalid(accumulatedError!!) } } @@ -765,12 +767,12 @@ sealed class Validated { inline fun traverseEither(fa: (A) -> Either): Either> = when (this) { - is Valid -> fa(this.a).map { Valid(it) } + is Valid -> fa(this.value).map { Valid(it) } is Invalid -> this.right() } inline fun traverseEither_(fa: (A) -> Either): Either = - fold({ Either.right(Unit) }, { fa(it).void() }) + fold({ Either.unit }, { fa(it).void() }) inline fun bifoldLeft( c: B, @@ -807,26 +809,18 @@ sealed class Validated { { "Validated.Valid($it)" } ) - data class Valid( - @Deprecated("Use value instead", ReplaceWith("value")) - val a: A - ) : Validated() { - val value: A = a - override fun toString(): String = "Validated.Valid($a)" + data class Valid(val value: A) : Validated() { + override fun toString(): String = "Validated.Valid($value)" } - data class Invalid( - @Deprecated("Use value instead", ReplaceWith("value")) - val e: E - ) : Validated() { - val value: E = e - override fun toString(): String = "Validated.Invalid($e)" + data class Invalid(val value: E) : Validated() { + override fun toString(): String = "Validated.Invalid($value)" } inline fun fold(fe: (E) -> B, fa: (A) -> B): B = when (this) { - is Valid -> fa(a) - is Invalid -> (fe(e)) + is Valid -> fa(value) + is Invalid -> (fe(value)) } val isValid = @@ -842,7 +836,7 @@ sealed class Validated { inline fun findOrNull(predicate: (A) -> Boolean): A? = when (this) { - is Valid -> if (predicate(this.a)) this.a else null + is Valid -> if (predicate(this.value)) this.value else null is Invalid -> null } @@ -917,7 +911,7 @@ sealed class Validated { fun foldRight(lb: Eval, f: (A, Eval) -> Eval): Eval = when (this) { - is Valid -> Eval.defer { f(this.a, lb) } + is Valid -> Eval.defer { f(this.value, lb) } is Invalid -> lb } @@ -997,9 +991,9 @@ fun Validated>.select(f: Validated B>): Vali fun Validated>.branch(fl: Validated C>, fr: Validated C>): Validated = when (this) { - is Validated.Valid -> when (val either = this.a) { - is Either.Left -> fl.map { f -> f(either.a) } - is Either.Right -> fr.map { f -> f(either.b) } + is Validated.Valid -> when (val either = this.value) { + is Either.Left -> fl.map { f -> f(either.value) } + is Either.Right -> fr.map { f -> f(either.value) } } is Validated.Invalid -> this } @@ -1070,12 +1064,12 @@ inline fun Validated.orElse(default: () -> Validated): Valida inline fun Validated.ap(SE: Semigroup, f: Validated B>): Validated = when (this) { is Validated.Valid -> when (f) { - is Validated.Valid -> Valid(f.a(this.a)) + is Validated.Valid -> Valid(f.value(this.value)) is Validated.Invalid -> f } is Validated.Invalid -> when (f) { is Validated.Valid -> this - is Validated.Invalid -> Invalid(SE.run { this@ap.e.combine(f.e) }) + is Validated.Invalid -> Invalid(SE.run { this@ap.value.combine(f.value) }) } } @@ -1092,19 +1086,19 @@ inline fun Validated.handleLeftWith(f: (E) -> Validated): Val inline fun Validated.handleErrorWith(f: (E) -> Validated): Validated = when (this) { is Validated.Valid -> this - is Validated.Invalid -> f(this.e) + is Validated.Invalid -> f(this.value) } inline fun Validated.handleError(f: (E) -> A): Validated = when (this) { is Validated.Valid -> this - is Validated.Invalid -> Valid(f(this.e)) + is Validated.Invalid -> Valid(f(this.value)) } inline fun Validated.redeem(fe: (E) -> B, fa: (A) -> B): Validated = when (this) { is Validated.Valid -> map(fa) - is Validated.Invalid -> Valid(fe(this.e)) + is Validated.Invalid -> Valid(fe(this.value)) } fun Validated.attempt(): Validated> = @@ -1116,8 +1110,8 @@ fun Validated.combine( y: Validated ): Validated = when { - this is Valid && y is Valid -> Valid(SA.run { a.combine(y.a) }) - this is Invalid && y is Invalid -> Invalid(SE.run { e.combine(y.e) }) + this is Valid && y is Valid -> Valid(SA.run { value.combine(y.value) }) + this is Invalid && y is Invalid -> Invalid(SE.run { value.combine(y.value) }) this is Invalid -> this else -> y } @@ -1126,7 +1120,7 @@ fun Validated.combineK(SE: Semigroup, y: Validated): Valid return when (this) { is Valid -> this is Invalid -> when (y) { - is Invalid -> Invalid(SE.run { this@combineK.e.combine(y.e) }) + is Invalid -> Invalid(SE.run { this@combineK.value.combine(y.value) }) is Valid -> y } } diff --git a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/computations/either.kt b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/computations/either.kt index 8a7b352934e..f4947a1ec11 100644 --- a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/computations/either.kt +++ b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/computations/either.kt @@ -2,7 +2,7 @@ package arrow.core.computations import arrow.continuations.Effect import arrow.core.Either -import arrow.core.Left +import arrow.core.Either.Left import arrow.core.Validated import arrow.core.right import kotlin.coroutines.RestrictsSuspension @@ -11,14 +11,14 @@ fun interface EitherEffect : Effect> { suspend fun Either.bind(): B = when (this) { - is Either.Right -> b + is Either.Right -> value is Either.Left -> control().shift(this@bind) } suspend fun Validated.bind(): B = when (this) { - is Validated.Valid -> a - is Validated.Invalid -> control().shift(Left(e)) + is Validated.Valid -> value + is Validated.Invalid -> control().shift(Left(value)) } @Deprecated("This operator is being deprecated due to confusion with Boolean, and unifying a single API. Use bind() instead.", ReplaceWith("bind()")) diff --git a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/computations/validated.kt b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/computations/validated.kt index 0230d2c9ff1..7023c9dfb90 100644 --- a/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/computations/validated.kt +++ b/arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/computations/validated.kt @@ -13,7 +13,7 @@ fun interface ValidatedEffect : Effect> { suspend fun Validated.bind(): B = when (this) { - is Validated.Valid -> a + is Validated.Valid -> value is Validated.Invalid -> control().shift(this@bind) } diff --git a/arrow-libs/core/arrow-core-data/src/test/kotlin/arrow/core/EitherTest.kt b/arrow-libs/core/arrow-core-data/src/test/kotlin/arrow/core/EitherTest.kt index 6afa1917566..48ee658a554 100644 --- a/arrow-libs/core/arrow-core-data/src/test/kotlin/arrow/core/EitherTest.kt +++ b/arrow-libs/core/arrow-core-data/src/test/kotlin/arrow/core/EitherTest.kt @@ -3,6 +3,8 @@ package arrow.core import arrow.core.computations.EitherEffect import arrow.core.computations.RestrictedEitherEffect import arrow.core.computations.either +import arrow.core.Either.Right +import arrow.core.Either.Left import arrow.core.test.UnitSpec import arrow.core.test.generators.any import arrow.core.test.generators.either diff --git a/arrow-libs/core/arrow-core-data/src/test/kotlin/arrow/core/OptionTest.kt b/arrow-libs/core/arrow-core-data/src/test/kotlin/arrow/core/OptionTest.kt index 2f1f02ffe09..a041cd4c3d6 100755 --- a/arrow-libs/core/arrow-core-data/src/test/kotlin/arrow/core/OptionTest.kt +++ b/arrow-libs/core/arrow-core-data/src/test/kotlin/arrow/core/OptionTest.kt @@ -16,7 +16,7 @@ import io.kotlintest.shouldNotBe class OptionTest : UnitSpec() { val some: Option = Some("kotlin") - val none: Option = Option.empty() + val none: Option = None init { diff --git a/arrow-libs/core/arrow-core-data/src/test/kotlin/arrow/core/ValidatedTest.kt b/arrow-libs/core/arrow-core-data/src/test/kotlin/arrow/core/ValidatedTest.kt index 83f30028380..6a6b714f9da 100644 --- a/arrow-libs/core/arrow-core-data/src/test/kotlin/arrow/core/ValidatedTest.kt +++ b/arrow-libs/core/arrow-core-data/src/test/kotlin/arrow/core/ValidatedTest.kt @@ -3,6 +3,8 @@ package arrow.core import arrow.core.computations.RestrictedValidatedEffect import arrow.core.computations.ValidatedEffect import arrow.core.computations.validated +import arrow.core.Either.Left +import arrow.core.Either.Right import arrow.core.test.UnitSpec import arrow.core.test.laws.FxLaws import arrow.typeclasses.Monoid @@ -184,7 +186,7 @@ class ValidatedTest : UnitSpec() { "catchNel should return Invalid(Nel(result)) when f throws" { val exception = MyException("Boom!") suspend fun loadFromNetwork(): Int = throw exception - Validated.catchNel { loadFromNetwork() } shouldBe Invalid(NonEmptyList(exception)) + Validated.catchNel { loadFromNetwork() } shouldBe Invalid(nonEmptyListOf(exception)) } "Cartesian builder should build products over homogeneous Validated" { diff --git a/arrow-libs/core/arrow-core-data/src/test/kotlin/arrow/typeclasses/TraverseTest.kt b/arrow-libs/core/arrow-core-data/src/test/kotlin/arrow/typeclasses/TraverseTest.kt index 3befcc13b8d..5d957ff1711 100644 --- a/arrow-libs/core/arrow-core-data/src/test/kotlin/arrow/typeclasses/TraverseTest.kt +++ b/arrow-libs/core/arrow-core-data/src/test/kotlin/arrow/typeclasses/TraverseTest.kt @@ -1,7 +1,7 @@ package arrow.typeclasses -import arrow.core.Left -import arrow.core.Right +import arrow.core.Either.Right +import arrow.core.Either.Left import arrow.core.sequenceEither import io.kotlintest.shouldBe import io.kotlintest.specs.StringSpec diff --git a/arrow-libs/core/arrow-core-test/src/main/kotlin/arrow/core/Try.kt b/arrow-libs/core/arrow-core-test/src/main/kotlin/arrow/core/Try.kt index 1b3ca30f343..cf4b0bf20a9 100644 --- a/arrow-libs/core/arrow-core-test/src/main/kotlin/arrow/core/Try.kt +++ b/arrow-libs/core/arrow-core-test/src/main/kotlin/arrow/core/Try.kt @@ -19,8 +19,8 @@ sealed class Try : TryOf { is Success -> { val b: Either = ev.value when (b) { - is Either.Left -> tailRecM(b.a, f) - is Either.Right -> Success(b.b) + is Either.Left -> tailRecM(b.value, f) + is Either.Right -> Success(b.value) } } } @@ -90,7 +90,7 @@ sealed class Try : TryOf { fun toOption(): Option = fold({ None }, { Some(it) }) - fun toEither(): Either = fold({ Left(it) }, { Right(it) }) + fun toEither(): Either = fold({ Either.Left(it) }, { Either.Right(it) }) fun toEither(onLeft: (Throwable) -> B): Either = this.toEither().fold({ onLeft(it).left() }, { it.right() }) diff --git a/arrow-libs/core/arrow-core-test/src/main/kotlin/arrow/core/test/generators/Generators.kt b/arrow-libs/core/arrow-core-test/src/main/kotlin/arrow/core/test/generators/Generators.kt index 9e5a516f3a7..a07b04f002e 100644 --- a/arrow-libs/core/arrow-core-test/src/main/kotlin/arrow/core/test/generators/Generators.kt +++ b/arrow-libs/core/arrow-core-test/src/main/kotlin/arrow/core/test/generators/Generators.kt @@ -5,12 +5,10 @@ import arrow.core.Either import arrow.core.Endo import arrow.core.Eval import arrow.core.Ior -import arrow.core.Left import arrow.core.ListK import arrow.core.MapK import arrow.core.NonEmptyList import arrow.core.Option -import arrow.core.Right import arrow.core.SequenceK import arrow.core.SetK import arrow.core.SortedMapK @@ -122,8 +120,8 @@ fun Gen.Companion.option(gen: Gen): Gen> = gen.orNull().map { it.toOption() } fun Gen.Companion.either(genE: Gen, genA: Gen): Gen> { - val genLeft = genE.map> { Left(it) } - val genRight = genA.map> { Right(it) } + val genLeft = genE.map> { Either.Left(it) } + val genRight = genA.map> { Either.Right(it) } return Gen.oneOf(genLeft, genRight) } diff --git a/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/iso/IsoSealed.kt b/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/iso/IsoSealed.kt index 0763c93f7fd..026b4a24817 100644 --- a/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/iso/IsoSealed.kt +++ b/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/iso/IsoSealed.kt @@ -1,11 +1,12 @@ package arrow.ap.objects.iso +import arrow.core.None import arrow.core.Option import arrow.optics.OpticsTarget import arrow.optics.optics @optics([OpticsTarget.ISO]) sealed class IsoSealed(val field: String, val nullable: String?, val option: Option) { - data class IsoSealed2(val a: String?) : IsoSealed("", null, Option.empty()) + data class IsoSealed2(val a: String?) : IsoSealed("", null, None) companion object } diff --git a/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/lens/LensSealed.kt b/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/lens/LensSealed.kt index 4300aa2475f..6b14cbdec7b 100644 --- a/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/lens/LensSealed.kt +++ b/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/lens/LensSealed.kt @@ -1,11 +1,12 @@ package arrow.ap.objects.lens +import arrow.core.None import arrow.core.Option import arrow.optics.OpticsTarget import arrow.optics.optics @optics([OpticsTarget.LENS]) sealed class LensSealed(val field: String, val nullable: String?, val option: Option) { - data class Lens2(val a: String?) : LensSealed("", null, Option.empty()) + data class Lens2(val a: String?) : LensSealed("", null, None) companion object } diff --git a/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/optional/OptionalSealed.kt b/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/optional/OptionalSealed.kt index 339828517a1..cae4f391f0d 100644 --- a/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/optional/OptionalSealed.kt +++ b/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/optional/OptionalSealed.kt @@ -1,11 +1,12 @@ package arrow.ap.objects.optional +import arrow.core.None import arrow.core.Option import arrow.optics.OpticsTarget import arrow.optics.optics @optics([OpticsTarget.OPTIONAL]) sealed class OptionalSealed(val field: String, val nullable: String?, val option: Option) { - data class Optional2(val a: String?) : OptionalSealed("", null, Option.empty()) + data class Optional2(val a: String?) : OptionalSealed("", null, None) companion object } diff --git a/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/prism/Prism.kt b/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/prism/Prism.kt index 81e9aef9b53..c359d24b094 100644 --- a/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/prism/Prism.kt +++ b/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/prism/Prism.kt @@ -1,12 +1,13 @@ package arrow.ap.objects.prism +import arrow.core.None import arrow.core.Option import arrow.optics.OpticsTarget import arrow.optics.optics @optics([OpticsTarget.PRISM]) sealed class Prism(val field: String, val nullable: String?, val option: Option) { - data class PrismSealed1(private val a: String?) : Prism("", a, Option.empty()) - data class PrismSealed2(private val b: String?) : Prism("", b, Option.empty()) + data class PrismSealed1(private val a: String?) : Prism("", a, None) + data class PrismSealed2(private val b: String?) : Prism("", b, None) companion object } diff --git a/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/prism/PrismWithoutCompanion.kt b/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/prism/PrismWithoutCompanion.kt index a83f848356e..1f363644b3a 100644 --- a/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/prism/PrismWithoutCompanion.kt +++ b/arrow-libs/core/arrow-meta/arrow-meta-test-models/src/main/java/arrow/ap/objects/prism/PrismWithoutCompanion.kt @@ -1,11 +1,12 @@ package arrow.ap.objects.prism +import arrow.core.None import arrow.core.Option import arrow.optics.OpticsTarget import arrow.optics.optics @optics([OpticsTarget.PRISM]) sealed class PrismWithoutCompanion(val field: String, val nullable: String?, val option: Option) { - data class PrismSealed1(private val a: String?) : PrismWithoutCompanion("", a, Option.empty()) - data class PrismSealed2(private val b: String?) : PrismWithoutCompanion("", b, Option.empty()) + data class PrismSealed1(private val a: String?) : PrismWithoutCompanion("", a, None) + data class PrismSealed2(private val b: String?) : PrismWithoutCompanion("", b, None) } diff --git a/arrow-libs/examples/src/test/kotlin/arrow/DataTypeExamples.kt b/arrow-libs/examples/src/test/kotlin/arrow/DataTypeExamples.kt index 5665bcce7a3..126b05ad0f8 100644 --- a/arrow-libs/examples/src/test/kotlin/arrow/DataTypeExamples.kt +++ b/arrow-libs/examples/src/test/kotlin/arrow/DataTypeExamples.kt @@ -5,7 +5,8 @@ import arrow.Problem.noReciprocal import arrow.Problem.somethingExploded import arrow.Problem.somethingWentWRong import arrow.core.Either -import arrow.core.Left +import arrow.core.Either.Left +import arrow.core.Either.Right import arrow.core.None import arrow.core.Option import arrow.core.Some @@ -64,14 +65,14 @@ class DataTypeExamples : FreeSpec() { // Either http://arrow.io/docs/apidocs/arrow-core-data/arrow.core/-either/ "Either left or right" - { fun parse(s: String): ProblemOrInt = try { - Either.right(s.toInt()) + Right(s.toInt()) } catch (e: Throwable) { - Either.left(invalidInt) + Left(invalidInt) } fun reciprocal(i: Int): Either = when (i) { 0 -> Left(noReciprocal) - else -> Either.Right(1.0 / i) + else -> Right(1.0 / i) } fun magic(s: String): Either = @@ -80,11 +81,11 @@ class DataTypeExamples : FreeSpec() { var either: ProblemOrInt "Right" { - either = Either.right(5) - either shouldBe Either.Right(5) + either = Right(5) + either shouldBe Right(5) either.getOrElse { 0 } shouldBe 5 - either.map { it + 1 } shouldBe Either.right(6) - either.flatMap { Either.right(6) } shouldBe Either.right(6) + either.map { it + 1 } shouldBe Right(6) + either.flatMap { Right(6) } shouldBe Right(6) either.flatMap { Left(somethingWentWRong) } shouldBe Left(somethingWentWRong) } @@ -99,13 +100,13 @@ class DataTypeExamples : FreeSpec() { "Either rather than exception" { parse("Not an number") shouldBe Left(invalidInt) - parse("2") shouldBe Either.right(2) + parse("2") shouldBe Right(2) } "Combinators" { magic("0") shouldBe Left(noReciprocal) magic("Not a number") shouldBe Left(invalidInt) - magic("1") shouldBe Either.right("1.0") + magic("1") shouldBe Right("1.0") } "Fold" { @@ -142,14 +143,14 @@ class DataTypeExamples : FreeSpec() { "Recover" { val gain = Either.catch { playLottery(99) } - gain.handleError { 0 } shouldBe Either.Right(0) + gain.handleError { 0 } shouldBe Right(0) gain.handleErrorWith { try { - Either.Right(playLottery(42)) + Right(playLottery(42)) } catch (e: Throwable) { Either.Left(e) } - } shouldBe Either.Right(1000) + } shouldBe Right(1000) } } } diff --git a/arrow-libs/fx/arrow-fx-coroutines-test/src/main/kotlin/arrow/fx/coroutines/predef-test.kt b/arrow-libs/fx/arrow-fx-coroutines-test/src/main/kotlin/arrow/fx/coroutines/predef-test.kt index 552eb4e9c1a..682ec0e406e 100644 --- a/arrow-libs/fx/arrow-fx-coroutines-test/src/main/kotlin/arrow/fx/coroutines/predef-test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines-test/src/main/kotlin/arrow/fx/coroutines/predef-test.kt @@ -198,25 +198,25 @@ fun leftException(e: Throwable): Matcher> = override fun test(value: Either): MatcherResult = when (value) { is Either.Left -> when { - value.a::class != e::class -> MatcherResult( + value.value::class != e::class -> MatcherResult( false, - "Expected exception of type ${e::class} but found ${value.a::class}", + "Expected exception of type ${e::class} but found ${value.value::class}", "Should not be exception of type ${e::class}" ) - value.a.message != e.message -> MatcherResult( + value.value.message != e.message -> MatcherResult( false, - "Expected exception with message ${e.message} but found ${value.a.message}", + "Expected exception with message ${e.message} but found ${value.value.message}", "Should not be exception with message ${e.message}" ) else -> MatcherResult( true, - "Expected exception of type ${e::class} and found ${value.a::class}", - "Expected exception of type ${e::class} and found ${value.a::class}" + "Expected exception of type ${e::class} and found ${value.value::class}", + "Expected exception of type ${e::class} and found ${value.value::class}" ) } is Either.Right -> MatcherResult( false, - "Expected Either.Left with exception of type ${e::class} and found Right with ${value.b}", + "Expected Either.Left with exception of type ${e::class} and found Right with ${value.value}", "Should not be Either.Left with exception" ) } @@ -227,20 +227,20 @@ fun either(e: Either): Matcher> = override fun test(value: Either): MatcherResult = when (value) { is Either.Left -> when { - value.a::class != (e.swap().orNull() ?: Int)::class -> MatcherResult( + value.value::class != (e.swap().orNull() ?: Int)::class -> MatcherResult( false, "Expected $e but found $value", "Should not be $e" ) - value.a.message != (e.swap().orNull()?.message ?: -1) -> MatcherResult( + value.value.message != (e.swap().orNull()?.message ?: -1) -> MatcherResult( false, "Expected $e but found $value", "Should not be $e" ) else -> MatcherResult( true, - "Expected exception of type ${e::class} and found ${value.a::class}", - "Expected exception of type ${e::class} and found ${value.a::class}" + "Expected exception of type ${e::class} and found ${value.value::class}", + "Expected exception of type ${e::class} and found ${value.value::class}" ) } is Either.Right -> equalityMatcher(e).test(value) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/CircuitBreaker.kt b/arrow-libs/fx/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/CircuitBreaker.kt index 4ccf111f374..58e4783ed41 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/CircuitBreaker.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/CircuitBreaker.kt @@ -105,11 +105,11 @@ private constructor( is Closed -> { when (result) { is Either.Right -> { - if (curr.failures == 0) result.b + if (curr.failures == 0) result.value else { // In case of success, must reset the failures counter! val update = Closed(0) if (!state.compareAndSet(curr, update)) markOrResetFailures(result) // retry? - else result.b + else result.value } } is Either.Left -> { @@ -119,7 +119,7 @@ private constructor( // It's fine, just increment the failures count val update = Closed(curr.failures + 1) if (!state.compareAndSet(curr, update)) markOrResetFailures(result) // retry? - else throw result.a + else throw result.value } else { // N.B. this could be canceled, however we don't care val now = System.currentTimeMillis() @@ -129,7 +129,7 @@ private constructor( if (!state.compareAndSet(curr, update)) markOrResetFailures(result) // retry else { onOpen.invoke() - throw result.a + throw result.value } } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/Race2.kt b/arrow-libs/fx/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/Race2.kt index e536dbc5add..87ef809f126 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/Race2.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/Race2.kt @@ -1,8 +1,6 @@ package arrow.fx.coroutines import arrow.core.Either -import arrow.core.Left -import arrow.core.Right import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.async import kotlinx.coroutines.cancelAndJoin @@ -35,7 +33,7 @@ import kotlin.coroutines.EmptyCoroutineContext * * val res = when(winner) { * is Either.Left -> "Never always loses race" - * is Either.Right -> "Race was won with ${winner.b}" + * is Either.Right -> "Race was won with ${winner.value}" * } * //sampleEnd * println(res) @@ -77,7 +75,7 @@ suspend inline fun raceN(crossinline fa: suspend () -> A, crossinline fb: * * val res = when(winner) { * is Either.Left -> "Never always loses race" - * is Either.Right -> "Race was won with ${winner.b}" + * is Either.Right -> "Race was won with ${winner.value}" * } * //sampleEnd * println(res) @@ -98,8 +96,8 @@ suspend inline fun raceN( val a = async(ctx) { fa() } val b = async(ctx) { fb() } select> { - a.onAwait.invoke { Left(it) } - b.onAwait.invoke { Right(it) } + a.onAwait.invoke { Either.Left(it) } + b.onAwait.invoke { Either.Right(it) } }.also { when (it) { is Either.Left -> b.cancelAndJoin() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/Resource.kt b/arrow-libs/fx/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/Resource.kt index d76e458bb12..06e60857537 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/Resource.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/Resource.kt @@ -305,9 +305,9 @@ sealed class Resource { when (res) { is Either.Left -> { r.release(res, ExitCase.Completed) - tailRecM(res.a, f) + tailRecM(res.value, f) } - is Either.Right -> Allocate({ res.b }, { _, ec -> r.release(res, ec) }) + is Either.Right -> Allocate({ res.value }, { _, ec -> r.release(res, ec) }) } } is Defer -> Defer { loop(r.resource.invoke()) } diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Prism.kt b/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Prism.kt index 0c6ef8a44ab..c80d089046c 100644 --- a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Prism.kt +++ b/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Prism.kt @@ -82,8 +82,8 @@ interface PPrism : POptional, PSetter, Fold< { it.fold({ a -> getOrModify(a).bimap({ Either.Left(it) }, { Either.Left(it) }) }, { c -> Either.Right(Either.Right(c)) }) }, { when (it) { - is Either.Left -> Either.Left(reverseGet(it.a)) - is Either.Right -> Either.Right(it.b) + is Either.Left -> Either.Left(reverseGet(it.value)) + is Either.Right -> Either.Right(it.value) } } ) diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/std/option.kt b/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/std/option.kt index 6d9bd04bc6a..256b2d836ce 100644 --- a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/std/option.kt +++ b/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/std/option.kt @@ -3,7 +3,7 @@ package arrow.optics import arrow.core.Either import arrow.core.None import arrow.core.Option -import arrow.core.Right +import arrow.core.Either.Right import arrow.core.Some import arrow.core.identity import arrow.typeclasses.Monoid diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/GetterTest.kt b/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/GetterTest.kt index e7aadfd1d84..503976b1921 100644 --- a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/GetterTest.kt +++ b/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/GetterTest.kt @@ -1,7 +1,7 @@ package arrow.optics -import arrow.core.Left -import arrow.core.Right +import arrow.core.Either.Left +import arrow.core.Either.Right import arrow.core.k import arrow.core.string import arrow.core.test.UnitSpec diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/LensTest.kt b/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/LensTest.kt index 171b03d5eb6..58cd7381105 100644 --- a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/LensTest.kt +++ b/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/LensTest.kt @@ -1,7 +1,7 @@ package arrow.optics -import arrow.core.Left -import arrow.core.Right +import arrow.core.Either.Left +import arrow.core.Either.Right import arrow.core.int import arrow.core.string import arrow.core.test.UnitSpec diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/OptionalTest.kt b/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/OptionalTest.kt index bf6b3066861..7059f5aaba4 100644 --- a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/OptionalTest.kt +++ b/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/OptionalTest.kt @@ -1,7 +1,7 @@ package arrow.optics -import arrow.core.Left -import arrow.core.Right +import arrow.core.Either.Left +import arrow.core.Either.Right import arrow.core.getOrElse import arrow.core.identity import arrow.core.int diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/EitherTest.kt b/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/EitherTest.kt index 2190423900d..2e5d49e8ee8 100644 --- a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/EitherTest.kt +++ b/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/EitherTest.kt @@ -23,14 +23,14 @@ class EitherTest : UnitSpec() { when (this) { is Invalid -> { when (b) { - is Invalid -> Invalid((e + b.e)) + is Invalid -> Invalid((value + b.value)) is Valid -> b } } is Valid -> { when (b) { is Invalid -> b - is Valid -> arrow.core.Valid((a + b.a)) + is Valid -> arrow.core.Valid((value + b.value)) } } } diff --git a/arrow-site/docs/_code/core-home-code.md b/arrow-site/docs/_code/core-home-code.md index 3212506ec97..babe7e8db23 100644 --- a/arrow-site/docs/_code/core-home-code.md +++ b/arrow-site/docs/_code/core-home-code.md @@ -4,8 +4,8 @@ library: core {: data-executable="true"} ```kotlin:ank import arrow.core.Either -import arrow.core.Left -import arrow.core.Right +import arrow.core.Either.Left +import arrow.core.Either.Right import arrow.core.computations.either object Lettuce diff --git a/arrow-site/docs/docs/datatypes/nonemptylist/README.md b/arrow-site/docs/docs/datatypes/nonemptylist/README.md index 27ca38c6bd4..8599077a235 100644 --- a/arrow-site/docs/docs/datatypes/nonemptylist/README.md +++ b/arrow-site/docs/docs/datatypes/nonemptylist/README.md @@ -28,9 +28,9 @@ import arrow.core.* A `NonEmptyList` guarantees the list always has at least 1 element. ```kotlin:ank:silent -NonEmptyList.of(1, 2, 3, 4, 5) // NonEmptyList -NonEmptyList.of(1, 2) // NonEmptyList -//NonEmptyList.of() // does not compile +nonEmptyListOf(1, 2, 3, 4, 5) // NonEmptyList +nonEmptyListOf(1, 2) // NonEmptyList +//nonEmptyListOf() // does not compile ``` ## head @@ -38,7 +38,7 @@ NonEmptyList.of(1, 2) // NonEmptyList Unlike `List#[0]`, `NonEmptyList#head` is a safe operation that guarantees no exception throwing. ```kotlin -NonEmptyList.of(1, 2, 3, 4, 5).head +nonEmptyListOf(1, 2, 3, 4, 5).head ``` ## foldLeft @@ -51,7 +51,7 @@ The second argument is a function that takes the current state and element in th fun sumNel(nel: NonEmptyList): Int = nel.foldLeft(0) { acc, n -> acc + n } -sumNel(NonEmptyList.of(1, 1, 1, 1)) +sumNel(nonEmptyListOf(1, 1, 1, 1)) ``` ## map @@ -59,7 +59,7 @@ sumNel(NonEmptyList.of(1, 1, 1, 1)) `map` allows us to transform `A` into `B` in `NonEmptyList< A >` ```kotlin:ank -NonEmptyList.of(1, 1, 1, 1).map { it + 1 } +nonEmptyListOf(1, 1, 1, 1).map { it + 1 } ``` ## flatMap @@ -67,8 +67,8 @@ NonEmptyList.of(1, 1, 1, 1).map { it + 1 } `flatMap` allows us to compute over the contents of multiple `NonEmptyList< * >` values ```kotlin:ank -val nelOne: NonEmptyList = NonEmptyList.of(1) -val nelTwo: NonEmptyList = NonEmptyList.of(2) +val nelOne: NonEmptyList = nonEmptyListOf(1) +val nelTwo: NonEmptyList = nonEmptyListOf(2) nelOne.flatMap { one -> nelTwo.map { two -> @@ -88,9 +88,9 @@ import java.util.* data class Person(val id: UUID, val name: String, val year: Int) // Note each NonEmptyList is of a different type -val nelId: NonEmptyList = NonEmptyList.of(UUID.randomUUID(), UUID.randomUUID()) -val nelName: NonEmptyList = NonEmptyList.of("William Alvin Howard", "Haskell Curry") -val nelYear: NonEmptyList = NonEmptyList.of(1926, 1900) +val nelId: NonEmptyList = nonEmptyListOf(UUID.randomUUID(), UUID.randomUUID()) +val nelName: NonEmptyList = nonEmptyListOf("William Alvin Howard", "Haskell Curry") +val nelYear: NonEmptyList = nonEmptyListOf(1926, 1900) NonEmptyList.mapN(nelId, nelName, nelYear) { id, name, year -> Person(id, name, year) @@ -100,6 +100,6 @@ NonEmptyList.mapN(nelId, nelName, nelYear) { id, name, year -> ### Summary - `NonEmptyList` is __used to model lists that guarantee at least one element__ -- We can easily construct values of `NonEmptyList` with `NonEmptyList.of` +- We can easily construct values of `NonEmptyList` with `nonEmptyListOf` - `foldLeft`, `map`, `flatMap`, and others are used to compute over the internal contents of a `NonEmptyList` value. - `NonEmptyList.mapN(..) { ... }` can be used to compute over multiple `NonEmptyList` values preserving type information and __abstracting over arity__ with `map` diff --git a/arrow-site/docs/docs/fold/README.md b/arrow-site/docs/docs/fold/README.md index 5668787e152..20605c15a90 100644 --- a/arrow-site/docs/docs/fold/README.md +++ b/arrow-site/docs/docs/fold/README.md @@ -31,13 +31,13 @@ fun nullableFold(): Fold = object : Fold { nullableFold().isEmpty(null) ``` ```kotlin:ank -Fold.nonEmptyList().combineAll(Monoid.int(), NonEmptyList.of(1, 2, 3)) +Fold.nonEmptyList().combineAll(Monoid.int(), nonEmptyListOf(1, 2, 3)) ``` ```kotlin:ank nullableFold().firstOrNull(null) ``` ```kotlin:ank -Fold.nonEmptyList().firstOrNull(NonEmptyList.of(1, 2, 3, 4)) +Fold.nonEmptyList().firstOrNull(nonEmptyListOf(1, 2, 3, 4)) ``` ## Composition @@ -47,8 +47,8 @@ Composing `Fold` can be used for accessing foci in nested structures. ```kotlin:ank val nestedNelFold: Fold>, NonEmptyList> = Fold.nonEmptyList() -val nestedNel = NonEmptyList.of(1, 2, 3, 4).map { - NonEmptyList.of(it, it) +val nestedNel = nonEmptyListOf(1, 2, 3, 4).map { + nonEmptyListOf(it, it) } (nestedNelFold compose Fold.nonEmptyList()).getAll(nestedNel) diff --git a/arrow-site/docs/docs/getter/README.md b/arrow-site/docs/docs/getter/README.md index 95eca03b766..d829a7fd265 100644 --- a/arrow-site/docs/docs/getter/README.md +++ b/arrow-site/docs/docs/getter/README.md @@ -29,7 +29,7 @@ fun nonEmptyListHead() = Getter, T> { it.head } -nonEmptyListHead().get(NonEmptyList.of(1, 2, 3, 4)) +nonEmptyListHead().get(nonEmptyListOf(1, 2, 3, 4)) ``` Or, from any of the optics defined in `arrow-optics` that allow getting its focus safely. diff --git a/arrow-site/docs/docs/io/README.md b/arrow-site/docs/docs/io/README.md index c4ef5863bcb..60e0d95c6c2 100644 --- a/arrow-site/docs/docs/io/README.md +++ b/arrow-site/docs/docs/io/README.md @@ -82,8 +82,8 @@ Let's assume following domain, and compare two snippets one using `IO = Right(Lettuce) fun getKnife(): Either = Right(Knife) fun lunch(knife: Knife, food: Lettuce): Either = Left(InsufficientAmountOfLettuce(5)) @@ -213,8 +216,8 @@ All values on the left side assume to be `Right` biased and, whenever a `Left` v ```kotlin:ank import arrow.core.Either -import arrow.core.Left -import arrow.core.Right +import arrow.core.Either.Left +import arrow.core.Either.Right import arrow.core.computations.either object Lettuce diff --git a/arrow-site/docs/docs/patterns/monadcomprehensions/README.md b/arrow-site/docs/docs/patterns/monadcomprehensions/README.md index 291ed3215a8..f7cd9138ae7 100644 --- a/arrow-site/docs/docs/patterns/monadcomprehensions/README.md +++ b/arrow-site/docs/docs/patterns/monadcomprehensions/README.md @@ -50,8 +50,8 @@ Let's see one example of the block `either` that uses [`Effect`]({{ '/arrow/cont ```kotlin:ank:playground import arrow.core.computations.either import arrow.core.Either -import arrow.core.Right -import arrow.core.Left +import arrow.core.Either.Left +import arrow.core.Either.Right import arrow.core.flatMap /* A simple model of student and a university */ @@ -155,7 +155,7 @@ This will blow up the stack and won't be obvious to users that our method can fa ```kotlin:ank:playground import arrow.core.computations.either -import arrow.core.Right +import arrow.core.Either.Left suspend fun test(): Either = either { @@ -174,7 +174,7 @@ The equivalent code without using comprehensions would look like: ```kotlin:ank:playground import arrow.core.flatMap -import arrow.core.Right +import arrow.core.Either.Left //sampleStart val x: Either = Right(1) @@ -192,8 +192,8 @@ With this new style, we can rewrite our original example of database fetching as ```kotlin:ank:playground import arrow.core.computations.either import arrow.core.Either -import arrow.core.Right -import arrow.core.Left +import arrow.core.Either.Left +import arrow.core.Either.Right import arrow.core.flatMap /* A simple model of student and a university */