Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CU-f34dk7 remove old mapN and expose new APIs #2292

Merged
merged 7 commits into from Mar 5, 2021
122 changes: 122 additions & 0 deletions arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/List.kt
Expand Up @@ -4,6 +4,128 @@ import arrow.typeclasses.Monoid
import arrow.typeclasses.Semigroup
import kotlin.collections.plus as _plus

inline fun <B, C, D> mapN(
b: Iterable<B>,
c: Iterable<C>,
map: (B, C) -> D
): List<D> =
mapN(b, c, unit, unit, unit, unit, unit, unit, unit, unit) { b, c, _, _, _, _, _, _, _, _ -> map(b, c) }

inline fun <B, C, D, E> mapN(
b: Iterable<B>,
c: Iterable<C>,
d: Iterable<D>,
map: (B, C, D) -> E
): List<E> =
mapN(b, c, d, unit, unit, unit, unit, unit, unit, unit) { b, c, d, _, _, _, _, _, _, _ -> map(b, c, d) }

inline fun <B, C, D, E, F> mapN(
b: Iterable<B>,
c: Iterable<C>,
d: Iterable<D>,
e: Iterable<E>,
map: (B, C, D, E) -> F
): List<F> =
mapN(b, c, d, e, unit, unit, unit, unit, unit, unit) { b, c, d, e, _, _, _, _, _, _ -> map(b, c, d, e) }

inline fun <B, C, D, E, F, G> mapN(
b: Iterable<B>,
c: Iterable<C>,
d: Iterable<D>,
e: Iterable<E>,
f: Iterable<F>,
map: (B, C, D, E, F) -> G
): List<G> =
mapN(b, c, d, e, f, unit, unit, unit, unit, unit) { b, c, d, e, f, _, _, _, _, _ -> map(b, c, d, e, f) }

inline fun <B, C, D, E, F, G, H> mapN(
b: Iterable<B>,
c: Iterable<C>,
d: Iterable<D>,
e: Iterable<E>,
f: Iterable<F>,
g: Iterable<G>,
map: (B, C, D, E, F, G) -> H
): List<H> =
mapN(b, c, d, e, f, g, unit, unit, unit, unit) { b, c, d, e, f, g, _, _, _, _ -> map(b, c, d, e, f, g) }

inline fun <B, C, D, E, F, G, H, I> mapN(
b: Iterable<B>,
c: Iterable<C>,
d: Iterable<D>,
e: Iterable<E>,
f: Iterable<F>,
g: Iterable<G>,
h: Iterable<H>,
map: (B, C, D, E, F, G, H) -> I
): List<I> =
mapN(b, c, d, e, f, g, h, unit, unit, unit) { b, c, d, e, f, g, h, _, _, _ -> map(b, c, d, e, f, g, h) }

inline fun <B, C, D, E, F, G, H, I, J> mapN(
b: Iterable<B>,
c: Iterable<C>,
d: Iterable<D>,
e: Iterable<E>,
f: Iterable<F>,
g: Iterable<G>,
h: Iterable<H>,
i: Iterable<I>,
map: (B, C, D, E, F, G, H, I) -> J
): List<J> =
mapN(b, c, d, e, f, g, h, i, unit, unit) { b, c, d, e, f, g, h, i, _, _ -> map(b, c, d, e, f, g, h, i) }

inline fun <B, C, D, E, F, G, H, I, J, K> mapN(
b: Iterable<B>,
c: Iterable<C>,
d: Iterable<D>,
e: Iterable<E>,
f: Iterable<F>,
g: Iterable<G>,
h: Iterable<H>,
i: Iterable<I>,
j: Iterable<J>,
map: (B, C, D, E, F, G, H, I, J) -> K
): List<K> =
mapN(b, c, d, e, f, g, h, i, j, unit) { b, c, d, e, f, g, h, i, j, _ -> map(b, c, d, e, f, g, h, i, j) }

inline fun <B, C, D, E, F, G, H, I, J, K, L> mapN(
b: Iterable<B>,
c: Iterable<C>,
d: Iterable<D>,
e: Iterable<E>,
f: Iterable<F>,
g: Iterable<G>,
h: Iterable<H>,
i: Iterable<I>,
j: Iterable<J>,
k: Iterable<K>,
map: (B, C, D, E, F, G, H, I, J, K) -> L
): List<L> {
val buffer = ArrayList<L>()
for (bb in b) {
for (cc in c) {
for (dd in d) {
for (ee in e) {
for (ff in f) {
for (gg in g) {
for (hh in h) {
for (ii in i) {
for (jj in j) {
for (kk in k) {
buffer.add(map(bb, cc, dd, ee, ff, gg, hh, ii, jj, kk))
}
}
}
}
}
}
}
}
}
}
return buffer
}

fun <A> Semigroup.Companion.list(): Semigroup<List<A>> =
Monoid.list()

Expand Down
@@ -1,14 +1,23 @@
package arrow.core

@Deprecated("ListK object is deprecated, and will be removed in 1.0.0")
object ListK {

@Deprecated(
"mapN for Iterable has become a top-level function.",
ReplaceWith("mapN(b, c, map)", "arrow.core.mapN")
)
inline fun <B, C, D> mapN(
b: Iterable<B>,
c: Iterable<C>,
map: (B, C) -> D
): List<D> =
mapN(b, c, unit, unit, unit, unit, unit, unit, unit, unit) { b, c, _, _, _, _, _, _, _, _ -> map(b, c) }

@Deprecated(
"mapN for Iterable has become a top-level function.",
ReplaceWith("mapN(b, c, d, map)", "arrow.core.mapN")
)
inline fun <B, C, D, E> mapN(
b: Iterable<B>,
c: Iterable<C>,
Expand All @@ -17,6 +26,10 @@ object ListK {
): List<E> =
mapN(b, c, d, unit, unit, unit, unit, unit, unit, unit) { b, c, d, _, _, _, _, _, _, _ -> map(b, c, d) }

@Deprecated(
"mapN for Iterable has become a top-level function.",
ReplaceWith("mapN(b, c, d, e, map)", "arrow.core.mapN")
)
inline fun <B, C, D, E, F> mapN(
b: Iterable<B>,
c: Iterable<C>,
Expand All @@ -26,6 +39,10 @@ object ListK {
): List<F> =
mapN(b, c, d, e, unit, unit, unit, unit, unit, unit) { b, c, d, e, _, _, _, _, _, _ -> map(b, c, d, e) }

@Deprecated(
"mapN for Iterable has become a top-level function.",
ReplaceWith("mapN(b, c, d, e, f, map)", "arrow.core.mapN")
)
inline fun <B, C, D, E, F, G> mapN(
b: Iterable<B>,
c: Iterable<C>,
Expand All @@ -36,6 +53,10 @@ object ListK {
): List<G> =
mapN(b, c, d, e, f, unit, unit, unit, unit, unit) { b, c, d, e, f, _, _, _, _, _ -> map(b, c, d, e, f) }

@Deprecated(
"mapN for Iterable has become a top-level function.",
ReplaceWith("mapN(b, c, d, e, f, g, map)", "arrow.core.mapN")
)
inline fun <B, C, D, E, F, G, H> mapN(
b: Iterable<B>,
c: Iterable<C>,
Expand All @@ -47,6 +68,10 @@ object ListK {
): List<H> =
mapN(b, c, d, e, f, g, unit, unit, unit, unit) { b, c, d, e, f, g, _, _, _, _ -> map(b, c, d, e, f, g) }

@Deprecated(
"mapN for Iterable has become a top-level function.",
ReplaceWith("mapN(b, c, d, e, f, g, h, map)", "arrow.core.mapN")
)
inline fun <B, C, D, E, F, G, H, I> mapN(
b: Iterable<B>,
c: Iterable<C>,
Expand All @@ -59,6 +84,10 @@ object ListK {
): List<I> =
mapN(b, c, d, e, f, g, h, unit, unit, unit) { b, c, d, e, f, g, h, _, _, _ -> map(b, c, d, e, f, g, h) }

@Deprecated(
"mapN for Iterable has become a top-level function.",
ReplaceWith("mapN(b, c, d, e, f, g, h, i, map)", "arrow.core.mapN")
)
inline fun <B, C, D, E, F, G, H, I, J> mapN(
b: Iterable<B>,
c: Iterable<C>,
Expand All @@ -72,6 +101,10 @@ object ListK {
): List<J> =
mapN(b, c, d, e, f, g, h, i, unit, unit) { b, c, d, e, f, g, h, i, _, _ -> map(b, c, d, e, f, g, h, i) }

@Deprecated(
"mapN for Iterable has become a top-level function.",
ReplaceWith("mapN(b, c, d, e, f, g, h, i, j, map)", "arrow.core.mapN")
)
inline fun <B, C, D, E, F, G, H, I, J, K> mapN(
b: Iterable<B>,
c: Iterable<C>,
Expand All @@ -86,6 +119,10 @@ object ListK {
): List<K> =
mapN(b, c, d, e, f, g, h, i, j, unit) { b, c, d, e, f, g, h, i, j, _ -> map(b, c, d, e, f, g, h, i, j) }

@Deprecated(
"mapN for Iterable has become a top-level function.",
ReplaceWith("mapN(b, c, d, e, f, g, h, i, j, k, map)", "arrow.core.mapN")
)
inline fun <B, C, D, E, F, G, H, I, J, K, L> mapN(
b: Iterable<B>,
c: Iterable<C>,
Expand Down
43 changes: 37 additions & 6 deletions arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/MapK.kt
@@ -1,7 +1,12 @@
package arrow.core

@Deprecated("MapK object is deprecated, and will be removed in 1.0.0")
object MapK {

@Deprecated(
"mapN for Map has become a top-level function.",
ReplaceWith("mapN(b, c, map)", "arrow.core.mapN")
)
inline fun <Key, B, C, D> mapN(
b: Map<Key, B>,
c: Map<Key, C>,
Expand All @@ -22,6 +27,10 @@ object MapK {
map(key, bb, cc)
}

@Deprecated(
"mapN for Map has become a top-level function.",
ReplaceWith("mapN(b, c, d, map)", "arrow.core.mapN")
)
inline fun <Key, B, C, D, E> mapN(
b: Map<Key, B>,
c: Map<Key, C>,
Expand All @@ -43,6 +52,10 @@ object MapK {
map(key, bb, cc, dd)
}

@Deprecated(
"mapN for Map has become a top-level function.",
ReplaceWith("mapN(b, c, d, e, map)", "arrow.core.mapN")
)
inline fun <Key, B, C, D, E, F> mapN(
b: Map<Key, B>,
c: Map<Key, C>,
Expand All @@ -65,6 +78,10 @@ object MapK {
map(key, bb, cc, dd, ee)
}

@Deprecated(
"mapN for Map has become a top-level function.",
ReplaceWith("mapN(b, c, d, e, f, map)", "arrow.core.mapN")
)
inline fun <Key, B, C, D, E, F, G> mapN(
b: Map<Key, B>,
c: Map<Key, C>,
Expand All @@ -88,6 +105,10 @@ object MapK {
map(key, bb, cc, dd, ee, ff)
}

@Deprecated(
"mapN for Map has become a top-level function.",
ReplaceWith("mapN(b, c, d, e, f, g, map)", "arrow.core.mapN")
)
inline fun <Key, B, C, D, E, F, G, H> mapN(
b: Map<Key, B>,
c: Map<Key, C>,
Expand All @@ -112,6 +133,10 @@ object MapK {
map(key, bb, cc, dd, ee, ff, gg)
}

@Deprecated(
"mapN for Map has become a top-level function.",
ReplaceWith("mapN(b, c, d, e, f, g, h, map)", "arrow.core.mapN")
)
inline fun <Key, B, C, D, E, F, G, H, I> mapN(
b: Map<Key, B>,
c: Map<Key, C>,
Expand All @@ -137,6 +162,10 @@ object MapK {
map(key, bb, cc, dd, ee, ff, gg, hh)
}

@Deprecated(
"mapN for Map has become a top-level function.",
ReplaceWith("mapN(b, c, d, e, f, g, h, i, map)", "arrow.core.mapN")
)
inline fun <Key, B, C, D, E, F, G, H, I, J> mapN(
b: Map<Key, B>,
c: Map<Key, C>,
Expand All @@ -163,6 +192,10 @@ object MapK {
map(key, bb, cc, dd, ee, ff, gg, hh, ii)
}

@Deprecated(
"mapN for Map has become a top-level function.",
ReplaceWith("mapN(b, c, d, e, f, g, h, i, j, map)", "arrow.core.mapN")
)
inline fun <Key, B, C, D, E, F, G, H, I, J, K> mapN(
b: Map<Key, B>,
c: Map<Key, C>,
Expand All @@ -179,6 +212,10 @@ object MapK {
map(key, bb, cc, dd, ee, ff, gg, hh, ii, jj)
}

@Deprecated(
"mapN for Map has become a top-level function.",
ReplaceWith("mapN(b, c, d, e, f, g, h, i, j, k, map)", "arrow.core.mapN")
)
inline fun <Key, B, C, D, E, F, G, H, I, J, K, L> mapN(
b: Map<Key, B>,
c: Map<Key, C>,
Expand Down Expand Up @@ -211,9 +248,3 @@ object MapK {
return destination
}
}

internal fun <K, A> Pair<K, A>?.asIterable(): Iterable<Pair<K, A>> =
when (this) {
null -> emptyList()
else -> listOf(this)
}
Expand Up @@ -49,39 +49,3 @@ object Nullable {
}
}
}

@Deprecated("Top-level mapN function for A? conflicts with other types such as List<A> and Map<K, V>", ReplaceWith("Nullable.mapN(a, fn", "arrow.core.mapN"))
inline fun <A, R> mapN(a: A?, fn: (A) -> R): R? =
Nullable.mapN(a, fn)

@Deprecated("Top-level mapN function for A? conflicts with other types such as List<A> and Map<K, V>", ReplaceWith("Nullable.mapN(a, b, fn", "arrow.core.mapN"))
inline fun <A, B, R> mapN(a: A?, b: B?, fn: (A, B) -> R): R? =
Nullable.mapN(a, b, fn)

@Deprecated("Top-level mapN function for A? conflicts with other types such as List<A> and Map<K, V>", ReplaceWith("Nullable.mapN(a, b, c, fn", "arrow.core.mapN"))
inline fun <A, B, C, R> mapN(a: A?, b: B?, c: C?, fn: (A, B, C) -> R): R? =
Nullable.mapN(a, b, c, fn)

@Deprecated("Top-level mapN function for A? conflicts with other types such as List<A> and Map<K, V>", ReplaceWith("Nullable.mapN(a, b, c, d, fn", "arrow.core.mapN"))
inline fun <A, B, C, D, R> mapN(a: A?, b: B?, c: C?, d: D?, fn: (A, B, C, D) -> R): R? =
Nullable.mapN(a, b, c, d, fn)

@Deprecated("Top-level mapN function for A? conflicts with other types such as List<A> and Map<K, V>", ReplaceWith("Nullable.mapN(a, b, c, d, e, fn", "arrow.core.mapN"))
inline fun <A, B, C, D, E, R> mapN(a: A?, b: B?, c: C?, d: D?, e: E?, fn: (A, B, C, D, E) -> R): R? =
Nullable.mapN(a, b, c, d, e, fn)

@Deprecated("Top-level mapN function for A? conflicts with other types such as List<A> and Map<K, V>", ReplaceWith("Nullable.mapN(a, b, c, d, e, f, fn", "arrow.core.mapN"))
inline fun <A, B, C, D, E, F, R> mapN(a: A?, b: B?, c: C?, d: D?, e: E?, f: F?, fn: (A, B, C, D, E, F) -> R): R? =
Nullable.mapN(a, b, c, d, e, f, fn)

@Deprecated("Top-level mapN function for A? conflicts with other types such as List<A> and Map<K, V>", ReplaceWith("Nullable.mapN(a, b, c, d, e, f, g, fn", "arrow.core.mapN"))
inline fun <A, B, C, D, E, F, G, R> mapN(a: A?, b: B?, c: C?, d: D?, e: E?, f: F?, g: G?, fn: (A, B, C, D, E, F, G) -> R): R? =
Nullable.mapN(a, b, c, d, e, f, g, fn)

@Deprecated("Top-level mapN function for A? conflicts with other types such as List<A> and Map<K, V>", ReplaceWith("Nullable.mapN(a, b, c, d, e, f, g, h, fn", "arrow.core.mapN"))
inline fun <A, B, C, D, E, F, G, H, R> mapN(a: A?, b: B?, c: C?, d: D?, e: E?, f: F?, g: G?, h: H?, fn: (A, B, C, D, E, F, G, H) -> R): R? =
Nullable.mapN(a, b, c, d, e, f, g, h, fn)

@Deprecated("Top-level mapN function for A? conflicts with other types such as List<A> and Map<K, V>", ReplaceWith("Nullable.mapN(a, b, c, d, e, f, g, h, i, fn", "arrow.core.mapN"))
inline fun <A, B, C, D, E, F, G, H, I, R> mapN(a: A?, b: B?, c: C?, d: D?, e: E?, f: F?, g: G?, h: H?, i: I?, fn: (A, B, C, D, E, F, G, H, I) -> R): R? =
Nullable.mapN(a, b, c, d, e, f, g, h, i, fn)