Skip to content

Commit 43eb33a

Browse files
authored
Move nullable mapN to Nullable, and deprecate top-level ones (#278)
1 parent 1ce60fa commit 43eb33a

File tree

1 file changed

+67
-27
lines changed
  • arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core

1 file changed

+67
-27
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,87 @@
11
@file:Suppress("NAME_SHADOWING")
2+
23
package arrow.core
34

5+
object Nullable {
6+
7+
inline fun <A, R> mapN(a: A?, fn: (A) -> R): R? =
8+
mapN(a, Unit) { a, _ -> fn(a) }
9+
10+
inline fun <A, B, R> mapN(a: A?, b: B?, fn: (A, B) -> R): R? =
11+
mapN(a, b, Unit) { a, b, _ -> fn(a, b) }
12+
13+
inline fun <A, B, C, R> mapN(a: A?, b: B?, c: C?, fn: (A, B, C) -> R): R? =
14+
mapN(a, b, c, Unit) { a, b, c, _ -> fn(a, b, c) }
15+
16+
inline fun <A, B, C, D, R> mapN(a: A?, b: B?, c: C?, d: D?, fn: (A, B, C, D) -> R): R? =
17+
mapN(a, b, c, d, Unit) { a, b, c, d, _ -> fn(a, b, c, d) }
18+
19+
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? =
20+
mapN(a, b, c, d, e, Unit) { a, b, c, d, e, _ -> fn(a, b, c, d, e) }
21+
22+
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? =
23+
mapN(a, b, c, d, e, f, Unit) { a, b, c, d, e, f, _ -> fn(a, b, c, d, e, f) }
24+
25+
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? =
26+
mapN(a, b, c, d, e, f, g, Unit) { a, b, c, d, e, f, g, _ -> fn(a, b, c, d, e, f, g) }
27+
28+
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? =
29+
mapN(a, b, c, d, e, f, g, h, Unit) { a, b, c, d, e, f, g, h, _ -> fn(a, b, c, d, e, f, g, h) }
30+
31+
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? =
32+
a?.let { a ->
33+
b?.let { b ->
34+
c?.let { c ->
35+
d?.let { d ->
36+
e?.let { e ->
37+
f?.let { f ->
38+
g?.let { g ->
39+
h?.let { h ->
40+
i?.let { i ->
41+
fn(a, b, c, d, e, f, g, h, i)
42+
}
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}
50+
}
51+
}
52+
53+
@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"))
454
inline fun <A, R> mapN(a: A?, fn: (A) -> R): R? =
5-
mapN(a, Unit) { a, _ -> fn(a) }
55+
Nullable.mapN(a, fn)
656

57+
@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"))
758
inline fun <A, B, R> mapN(a: A?, b: B?, fn: (A, B) -> R): R? =
8-
mapN(a, b, Unit) { a, b, _ -> fn(a, b) }
59+
Nullable.mapN(a, b, fn)
960

61+
@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"))
1062
inline fun <A, B, C, R> mapN(a: A?, b: B?, c: C?, fn: (A, B, C) -> R): R? =
11-
mapN(a, b, c, Unit) { a, b, c, _ -> fn(a, b, c) }
63+
Nullable.mapN(a, b, c, fn)
1264

65+
@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"))
1366
inline fun <A, B, C, D, R> mapN(a: A?, b: B?, c: C?, d: D?, fn: (A, B, C, D) -> R): R? =
14-
mapN(a, b, c, d, Unit) { a, b, c, d, _ -> fn(a, b, c, d) }
67+
Nullable.mapN(a, b, c, d, fn)
1568

69+
@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"))
1670
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? =
17-
mapN(a, b, c, d, e, Unit) { a, b, c, d, e, _ -> fn(a, b, c, d, e) }
71+
Nullable.mapN(a, b, c, d, e, fn)
1872

73+
@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"))
1974
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? =
20-
mapN(a, b, c, d, e, f, Unit) { a, b, c, d, e, f, _ -> fn(a, b, c, d, e, f) }
75+
Nullable.mapN(a, b, c, d, e, f, fn)
2176

77+
@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"))
2278
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? =
23-
mapN(a, b, c, d, e, f, g, Unit) { a, b, c, d, e, f, g, _ -> fn(a, b, c, d, e, f, g) }
79+
Nullable.mapN(a, b, c, d, e, f, g, fn)
2480

81+
@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"))
2582
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? =
26-
mapN(a, b, c, d, e, f, g, h, Unit) { a, b, c, d, e, f, g, h, _ -> fn(a, b, c, d, e, f, g, h) }
83+
Nullable.mapN(a, b, c, d, e, f, g, h, fn)
2784

85+
@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"))
2886
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? =
29-
a?.let { a ->
30-
b?.let { b ->
31-
c?.let { c ->
32-
d?.let { d ->
33-
e?.let { e ->
34-
f?.let { f ->
35-
g?.let { g ->
36-
h?.let { h ->
37-
i?.let { i ->
38-
fn(a, b, c, d, e, f, g, h, i)
39-
}
40-
}
41-
}
42-
}
43-
}
44-
}
45-
}
46-
}
47-
}
87+
Nullable.mapN(a, b, c, d, e, f, g, h, i, fn)

0 commit comments

Comments
 (0)