Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Unify syntax for extracting inner values #338

Merged
merged 4 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions arrow-core-data/src/main/kotlin/arrow/core/Either.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,11 @@ sealed class Either<out A, out B> : EitherOf<A, B> {
* The left side of the disjoint union, as opposed to the [Right] side.
*/
@Suppress("DataClassPrivateConstructor")
data class Left<out A> @PublishedApi internal constructor(val a: A) : Either<A, Nothing>() {
data class Left<out A> @PublishedApi internal constructor(
raulraja marked this conversation as resolved.
Show resolved Hide resolved
@Deprecated("Use value instead", ReplaceWith("value"))
val a: A
) : Either<A, Nothing>() {
val value: A = a
override val isLeft = true
override val isRight = false

Expand All @@ -1082,7 +1086,11 @@ sealed class Either<out A, out B> : EitherOf<A, B> {
* The right side of the disjoint union, as opposed to the [Left] side.
*/
@Suppress("DataClassPrivateConstructor")
data class Right<out B> @PublishedApi internal constructor(val b: B) : Either<Nothing, B>() {
data class Right<out B> @PublishedApi internal constructor(
@Deprecated("Use value instead", ReplaceWith("value"))
val b: B
) : Either<Nothing, B>() {
val value: B = b
override val isLeft = false
override val isRight = true

Expand Down
2 changes: 1 addition & 1 deletion arrow-core-data/src/main/kotlin/arrow/core/Ior.kt
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ sealed class Ior<out A, out B> : IorOf<A, B> {
override val isLeft: Boolean get() = false
override val isBoth: Boolean get() = true

override fun toString(): String = "Ior.Both($leftValue, rightValue)"
override fun toString(): String = "Ior.Both($leftValue, $rightValue)"
}

@Deprecated(
Expand Down
6 changes: 5 additions & 1 deletion arrow-core-data/src/main/kotlin/arrow/core/Option.kt
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,11 @@ object None : Option<Nothing>() {
override fun toString(): String = "Option.None"
}

data class Some<out T>(val t: T) : Option<T>() {
data class Some<out T>(
@Deprecated("Use value instead", ReplaceWith("value"))
val t: T
) : Option<T>() {
val value: T = t
override fun isEmpty() = false

override fun toString(): String = "Option.Some($t)"
Expand Down
40 changes: 36 additions & 4 deletions arrow-core-data/src/main/kotlin/arrow/core/Tuple10.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,39 @@ typealias Tuple10PartialOf<A, B, C, D, E, F, G, H, I> = arrow.Kind9<ForTuple10,
inline fun <A, B, C, D, E, F, G, H, I, J> Tuple10Of<A, B, C, D, E, F, G, H, I, J>.fix(): Tuple10<A, B, C, D, E, F, G, H, I, J> =
this as Tuple10<A, B, C, D, E, F, G, H, I, J>

data class Tuple10<out A, out B, out C, out D, out E, out F, out G, out H, out I, out J>(val a: A, val b: B, val c: C, val d: D, val e: E, val f: F, val g: G, val h: H, val i: I, val j: J) : Tuple10Of<A, B, C, D, E, F, G, H, I, J> {
data class Tuple10<out A, out B, out C, out D, out E, out F, out G, out H, out I, out J>(
@Deprecated("Use first instead", ReplaceWith("first"))
val a: A,
@Deprecated("Use second instead", ReplaceWith("second"))
val b: B,
@Deprecated("Use third instead", ReplaceWith("third"))
val c: C,
@Deprecated("Use fourth instead", ReplaceWith("fourth"))
val d: D,
@Deprecated("Use fifth instead", ReplaceWith("fifth"))
val e: E,
@Deprecated("Use sixth instead", ReplaceWith("sixth"))
val f: F,
@Deprecated("Use seventh instead", ReplaceWith("seventh"))
val g: G,
@Deprecated("Use eighth instead", ReplaceWith("eighth"))
val h: H,
@Deprecated("Use ninth instead", ReplaceWith("ninth"))
val i: I,
@Deprecated("Use tenth instead", ReplaceWith("tenth"))
val j: J
) : Tuple10Of<A, B, C, D, E, F, G, H, I, J> {

val first: A = a
val second: B = b
val third: C = c
val fourth: D = d
val fifth: E = e
val sixth: F = f
val seventh: G = g
val eight: H = h
nomisRev marked this conversation as resolved.
Show resolved Hide resolved
val ninth: I = i
val tenth: J = j

@Deprecated(ShowDeprecation)
fun show(SA: Show<A>, SB: Show<B>, SC: Show<C>, SD: Show<D>, SE: Show<E>, SF: Show<F>, SG: Show<G>, SH: Show<H>, SI: Show<I>, SJ: Show<J>): String =
Expand Down Expand Up @@ -134,12 +166,12 @@ operator fun <A : Comparable<A>, B : Comparable<B>, C : Comparable<C>, D : Compa
if (sixth == 0) {
val seventh = g.compareTo(other.g)
if (seventh == 0) {
val eigth = h.compareTo(other.h)
if (eigth == 0) {
val eighth = h.compareTo(other.h)
if (eighth == 0) {
val ninth = i.compareTo(other.i)
if (ninth == 0) j.compareTo(other.j)
else ninth
} else eigth
} else eighth
} else seventh
} else sixth
} else fifth
Expand Down
16 changes: 15 additions & 1 deletion arrow-core-data/src/main/kotlin/arrow/core/Tuple4.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,21 @@ typealias Tuple4PartialOf<A, B, C> = arrow.Kind3<ForTuple4, A, B, C>
inline fun <A, B, C, D> Tuple4Of<A, B, C, D>.fix(): Tuple4<A, B, C, D> =
this as Tuple4<A, B, C, D>

data class Tuple4<out A, out B, out C, out D>(val a: A, val b: B, val c: C, val d: D) : Tuple4Of<A, B, C, D> {
data class Tuple4<out A, out B, out C, out D>(
@Deprecated("Use first instead", ReplaceWith("first"))
val a: A,
@Deprecated("Use second instead", ReplaceWith("second"))
val b: B,
@Deprecated("Use third instead", ReplaceWith("third"))
val c: C,
@Deprecated("Use fourth instead", ReplaceWith("fourth"))
val d: D
) : Tuple4Of<A, B, C, D> {

val first: A = a
val second: B = b
val third: C = c
val fourth: D = d

@Deprecated(ShowDeprecation)
fun show(SA: Show<A>, SB: Show<B>, SC: Show<C>, SD: Show<D>): String =
Expand Down
19 changes: 18 additions & 1 deletion arrow-core-data/src/main/kotlin/arrow/core/Tuple5.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,24 @@ typealias Tuple5PartialOf<A, B, C, D> = arrow.Kind4<ForTuple5, A, B, C, D>
inline fun <A, B, C, D, E> Tuple5Of<A, B, C, D, E>.fix(): Tuple5<A, B, C, D, E> =
this as Tuple5<A, B, C, D, E>

data class Tuple5<out A, out B, out C, out D, out E>(val a: A, val b: B, val c: C, val d: D, val e: E) : Tuple5Of<A, B, C, D, E> {
data class Tuple5<out A, out B, out C, out D, out E>(
@Deprecated("Use first instead", ReplaceWith("first"))
val a: A,
@Deprecated("Use second instead", ReplaceWith("second"))
val b: B,
@Deprecated("Use third instead", ReplaceWith("third"))
val c: C,
@Deprecated("Use fourth instead", ReplaceWith("fourth"))
val d: D,
@Deprecated("Use fifth instead", ReplaceWith("fifth"))
val e: E
) : Tuple5Of<A, B, C, D, E> {

val first: A = a
val second: B = b
val third: C = c
val fourth: D = d
val fifth: E = e

@Deprecated(ShowDeprecation)
fun show(SA: Show<A>, SB: Show<B>, SC: Show<C>, SD: Show<D>, SE: Show<E>): String =
Expand Down
23 changes: 22 additions & 1 deletion arrow-core-data/src/main/kotlin/arrow/core/Tuple6.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,28 @@ typealias Tuple6PartialOf<A, B, C, D, E> = arrow.Kind5<ForTuple6, A, B, C, D, E>
inline fun <A, B, C, D, E, F> Tuple6Of<A, B, C, D, E, F>.fix(): Tuple6<A, B, C, D, E, F> =
this as Tuple6<A, B, C, D, E, F>

data class Tuple6<out A, out B, out C, out D, out E, out F>(val a: A, val b: B, val c: C, val d: D, val e: E, val f: F) : Tuple6Of<A, B, C, D, E, F> {
data class Tuple6<out A, out B, out C, out D, out E, out F>(
@Deprecated("Use first instead", ReplaceWith("first"))
val a: A,
@Deprecated("Use second instead", ReplaceWith("second"))
val b: B,
@Deprecated("Use third instead", ReplaceWith("third"))
val c: C,
@Deprecated("Use fourth instead", ReplaceWith("fourth"))
val d: D,
@Deprecated("Use fifth instead", ReplaceWith("fifth"))
val e: E,
@Deprecated("Use sixth instead", ReplaceWith("sixth"))
val f: F
) : Tuple6Of<A, B, C, D, E, F> {

val first: A = a
val second: B = b
val third: C = c
val fourth: D = d
val fifth: E = e
val sixth: F = f

@Deprecated(ShowDeprecation)
fun show(SA: Show<A>, SB: Show<B>, SC: Show<C>, SD: Show<D>, SE: Show<E>, SF: Show<F>): String =
"(" + listOf(SA.run { a.show() }, SB.run { b.show() }, SC.run { c.show() }, SD.run { d.show() }, SE.run { e.show() }, SF.run { f.show() }).joinToString(", ") + ")"
Expand Down
26 changes: 25 additions & 1 deletion arrow-core-data/src/main/kotlin/arrow/core/Tuple7.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,31 @@ typealias Tuple7PartialOf<A, B, C, D, E, F> = arrow.Kind6<ForTuple7, A, B, C, D,
inline fun <A, B, C, D, E, F, G> Tuple7Of<A, B, C, D, E, F, G>.fix(): Tuple7<A, B, C, D, E, F, G> =
this as Tuple7<A, B, C, D, E, F, G>

data class Tuple7<out A, out B, out C, out D, out E, out F, out G>(val a: A, val b: B, val c: C, val d: D, val e: E, val f: F, val g: G) : Tuple7Of<A, B, C, D, E, F, G> {
data class Tuple7<out A, out B, out C, out D, out E, out F, out G>(
@Deprecated("Use first instead", ReplaceWith("first"))
val a: A,
@Deprecated("Use second instead", ReplaceWith("second"))
val b: B,
@Deprecated("Use third instead", ReplaceWith("third"))
val c: C,
@Deprecated("Use fourth instead", ReplaceWith("fourth"))
val d: D,
@Deprecated("Use fifth instead", ReplaceWith("fifth"))
val e: E,
@Deprecated("Use sixth instead", ReplaceWith("sixth"))
val f: F,
@Deprecated("Use seventh instead", ReplaceWith("seventh"))
val g: G
) : Tuple7Of<A, B, C, D, E, F, G> {

val first: A = a
val second: B = b
val third: C = c
val fourth: D = d
val fifth: E = e
val sixth: F = f
val seventh: G = g

@Deprecated(ShowDeprecation)
fun show(SA: Show<A>, SB: Show<B>, SC: Show<C>, SD: Show<D>, SE: Show<E>, SF: Show<F>, SG: Show<G>): String =
"(" + listOf(SA.run { a.show() }, SB.run { b.show() }, SC.run { c.show() }, SD.run { d.show() }, SE.run { e.show() }, SF.run { f.show() }, SG.run { g.show() }).joinToString(", ") + ")"
Expand Down
29 changes: 28 additions & 1 deletion arrow-core-data/src/main/kotlin/arrow/core/Tuple8.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,34 @@ typealias Tuple8PartialOf<A, B, C, D, E, F, G> = arrow.Kind7<ForTuple8, A, B, C,
inline fun <A, B, C, D, E, F, G, H> Tuple8Of<A, B, C, D, E, F, G, H>.fix(): Tuple8<A, B, C, D, E, F, G, H> =
this as Tuple8<A, B, C, D, E, F, G, H>

data class Tuple8<out A, out B, out C, out D, out E, out F, out G, out H>(val a: A, val b: B, val c: C, val d: D, val e: E, val f: F, val g: G, val h: H) : Tuple8Of<A, B, C, D, E, F, G, H> {
data class Tuple8<out A, out B, out C, out D, out E, out F, out G, out H>(
@Deprecated("Use first instead", ReplaceWith("first"))
val a: A,
@Deprecated("Use second instead", ReplaceWith("second"))
val b: B,
@Deprecated("Use third instead", ReplaceWith("third"))
val c: C,
@Deprecated("Use fourth instead", ReplaceWith("fourth"))
val d: D,
@Deprecated("Use fifth instead", ReplaceWith("fifth"))
val e: E,
@Deprecated("Use sixth instead", ReplaceWith("sixth"))
val f: F,
@Deprecated("Use seventh instead", ReplaceWith("seventh"))
val g: G,
@Deprecated("Use eighth instead", ReplaceWith("eigth"))
nomisRev marked this conversation as resolved.
Show resolved Hide resolved
val h: H
) : Tuple8Of<A, B, C, D, E, F, G, H> {

val first: A = a
val second: B = b
val third: C = c
val fourth: D = d
val fifth: E = e
val sixth: F = f
val seventh: G = g
val eight: H = h
nomisRev marked this conversation as resolved.
Show resolved Hide resolved

@Deprecated(ShowDeprecation)
fun show(SA: Show<A>, SB: Show<B>, SC: Show<C>, SD: Show<D>, SE: Show<E>, SF: Show<F>, SG: Show<G>, SH: Show<H>): String =
"(" + listOf(SA.run { a.show() }, SB.run { b.show() }, SC.run { c.show() }, SD.run { d.show() }, SE.run { e.show() }, SF.run { f.show() }, SG.run { g.show() }, SH.run { h.show() }).joinToString(", ") + ")"
Expand Down
38 changes: 34 additions & 4 deletions arrow-core-data/src/main/kotlin/arrow/core/Tuple9.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,37 @@ typealias Tuple9PartialOf<A, B, C, D, E, F, G, H> = arrow.Kind8<ForTuple9, A, B,
inline fun <A, B, C, D, E, F, G, H, I> Tuple9Of<A, B, C, D, E, F, G, H, I>.fix(): Tuple9<A, B, C, D, E, F, G, H, I> =
this as Tuple9<A, B, C, D, E, F, G, H, I>

data class Tuple9<out A, out B, out C, out D, out E, out F, out G, out H, out I>(val a: A, val b: B, val c: C, val d: D, val e: E, val f: F, val g: G, val h: H, val i: I) : Tuple9Of<A, B, C, D, E, F, G, H, I> {
data class Tuple9<out A, out B, out C, out D, out E, out F, out G, out H, out I>(
@Deprecated("Use first instead", ReplaceWith("first"))
val a: A,
@Deprecated("Use second instead", ReplaceWith("second"))
val b: B,
@Deprecated("Use third instead", ReplaceWith("third"))
val c: C,
@Deprecated("Use fourth instead", ReplaceWith("fourth"))
val d: D,
@Deprecated("Use fifth instead", ReplaceWith("fifth"))
val e: E,
@Deprecated("Use sixth instead", ReplaceWith("sixth"))
val f: F,
@Deprecated("Use seventh instead", ReplaceWith("seventh"))
val g: G,
@Deprecated("Use eighth instead", ReplaceWith("eighth"))
val h: H,
@Deprecated("Use ninth instead", ReplaceWith("ninth"))
val i: I
) : Tuple9Of<A, B, C, D, E, F, G, H, I> {

val first: A = a
val second: B = b
val third: C = c
val fourth: D = d
val fifth: E = e
val sixth: F = f
val seventh: G = g
val eight: H = h
nomisRev marked this conversation as resolved.
Show resolved Hide resolved
val ninth: I = i

@Deprecated(ShowDeprecation)
fun show(SA: Show<A>, SB: Show<B>, SC: Show<C>, SD: Show<D>, SE: Show<E>, SF: Show<F>, SG: Show<G>, SH: Show<H>, SI: Show<I>): String =
"(" + listOf(SA.run { a.show() }, SB.run { b.show() }, SC.run { c.show() }, SD.run { d.show() }, SE.run { e.show() }, SF.run { f.show() }, SG.run { g.show() }, SH.run { h.show() }, SI.run { i.show() }).joinToString(", ") + ")"
Expand Down Expand Up @@ -126,9 +156,9 @@ operator fun <A : Comparable<A>, B : Comparable<B>, C : Comparable<C>, D : Compa
if (sixth == 0) {
val seventh = g.compareTo(other.g)
if (seventh == 0) {
val eigth = h.compareTo(other.h)
if (eigth == 0) i.compareTo(other.i)
else eigth
val eighth = h.compareTo(other.h)
if (eighth == 0) i.compareTo(other.i)
else eighth
} else seventh
} else sixth
} else fifth
Expand Down
Loading