File tree Expand file tree Collapse file tree 5 files changed +52
-0
lines changed
main/kotlin/com/javiersc/kotlin/stdlib
test/kotlin/com/javiersc/kotlin/stdlib Expand file tree Collapse file tree 5 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 4
4
5
5
### Added
6
6
7
+ - ` T?.or(other: T): T `
8
+ - ` T?.or(block: () -> T): T `
7
9
- ` Iterable<T>.sixth(): T `
8
10
- ` Iterable<T>.sixthOrNull(): T? `
9
11
- ` Iterable<T>.seventh(): T `
Original file line number Diff line number Diff line change @@ -209,6 +209,8 @@ public final class com/javiersc/kotlin/stdlib/StringsTransformKt {
209
209
public final class com/javiersc/kotlin/stdlib/TKt {
210
210
public static final fun ifNotNull (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
211
211
public static final fun ifNull (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
212
+ public static final fun or (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
213
+ public static final fun or (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
212
214
}
213
215
214
216
public abstract interface class com/javiersc/kotlin/stdlib/graph/Graph : java/util/Map, kotlin/jvm/internal/markers/KMappedMarker {
Original file line number Diff line number Diff line change @@ -215,6 +215,8 @@ public final class com/javiersc/kotlin/stdlib/StringsTransformKt {
215
215
public final class com/javiersc/kotlin/stdlib/TKt {
216
216
public static final fun ifNotNull (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
217
217
public static final fun ifNull (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
218
+ public static final fun or (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
219
+ public static final fun or (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
218
220
}
219
221
220
222
public abstract interface class com/javiersc/kotlin/stdlib/graph/Graph : java/util/Map, kotlin/jvm/internal/markers/KMappedMarker {
Original file line number Diff line number Diff line change @@ -9,3 +9,7 @@ public inline fun <T> T?.ifNull(block: () -> Unit): T? {
9
9
if (this == null ) block()
10
10
return this
11
11
}
12
+
13
+ public inline infix fun <T > T?.or (other : T ): T = this ? : other
14
+
15
+ public inline infix fun <T > T?.or (block : () -> T ): T = this ? : block()
Original file line number Diff line number Diff line change @@ -47,4 +47,46 @@ class TTest {
47
47
assertFalse { isOne }
48
48
assertTrue { isTwo }
49
49
}
50
+
51
+ @Test
52
+ fun or () {
53
+ val aa = a.or { " aa" }
54
+ val aaa = a.or (" aaa" )
55
+ val bb = b.or { " bb" }
56
+ val bbb = b.or (" bbb" )
57
+ val eleven = one.or { 11 }
58
+ val oneHundredEleven = one.or (111 )
59
+ val twentyTwo = two.or { 22 }
60
+ val twoHundredTwentyTwo = two.or (222 )
61
+
62
+ assertTrue { aa == " a" }
63
+ assertTrue { aaa == " a" }
64
+ assertTrue { bb == " bb" }
65
+ assertTrue { bbb == " bbb" }
66
+ assertTrue { eleven == 1 }
67
+ assertTrue { oneHundredEleven == 1 }
68
+ assertTrue { twentyTwo == 22 }
69
+ assertTrue { twoHundredTwentyTwo == 222 }
70
+ }
71
+
72
+ @Test
73
+ fun infixOr () {
74
+ val aa = a or { " aa" }
75
+ val aaa = a or " aaa"
76
+ val bb = b or { " bb" }
77
+ val bbb = b or " bbb"
78
+ val eleven = one or { 11 }
79
+ val oneHundredEleven = one or 111
80
+ val twentyTwo = two or { 22 }
81
+ val twoHundredTwentyTwo = two or 222
82
+
83
+ assertTrue { aa == " a" }
84
+ assertTrue { aaa == " a" }
85
+ assertTrue { bb == " bb" }
86
+ assertTrue { bbb == " bbb" }
87
+ assertTrue { eleven == 1 }
88
+ assertTrue { oneHundredEleven == 1 }
89
+ assertTrue { twentyTwo == 22 }
90
+ assertTrue { twoHundredTwentyTwo == 222 }
91
+ }
50
92
}
You can’t perform that action at this time.
0 commit comments