Skip to content

Commit 46e4b47

Browse files
committed
feat(json): better return type for shortcut operators
1 parent eb138d9 commit 46e4b47

2 files changed

Lines changed: 36 additions & 36 deletions

File tree

module-extkt-json/src/commonMain/kotlin/JsonArrayLike.kt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,77 +29,77 @@ fun JsonArrayLike.copy(block: MutableJsonArrayLike.() -> Unit): JsonArray {
2929
//
3030

3131
/** return the combination of [this] and the given [value] */
32-
operator fun JsonArrayLike.plus(value: JsonObjectLike?): JsonArrayLike {
32+
operator fun JsonArrayLike.plus(value: JsonObjectLike?): JsonArray {
3333
val element = value?.toJsonObject().orJsonNull()
34-
return this + element
34+
return JsonArray(this + element)
3535
}
3636

3737
/** return the combination of [this] and the given [value] */
38-
operator fun JsonArrayLike.plus(value: JsonArrayLike?): JsonArrayLike {
38+
operator fun JsonArrayLike.plus(value: JsonArrayLike?): JsonArray {
3939
val element = value?.toJsonArray().orJsonNull()
40-
return this + element
40+
return JsonArray(this + element)
4141
}
4242

4343
/** return the combination of [this] and the given [value] */
44-
operator fun JsonArrayLike.plus(value: String?): JsonArrayLike {
44+
operator fun JsonArrayLike.plus(value: String?): JsonArray {
4545
val element = JsonPrimitive(value)
46-
return this + element
46+
return JsonArray(this + element)
4747
}
4848

4949
/** return the combination of [this] and the given [value] */
50-
operator fun JsonArrayLike.plus(value: Number?): JsonArrayLike {
50+
operator fun JsonArrayLike.plus(value: Number?): JsonArray {
5151
val element = JsonPrimitive(value)
52-
return this + element
52+
return JsonArray(this + element)
5353
}
5454

5555
/** return the combination of [this] and the given [value] */
56-
operator fun JsonArrayLike.plus(value: Boolean?): JsonArrayLike {
56+
operator fun JsonArrayLike.plus(value: Boolean?): JsonArray {
5757
val element = JsonPrimitive(value)
58-
return this + element
58+
return JsonArray(this + element)
5959
}
6060

6161
/** return the combination of [this] and the given [value] */
62-
operator fun JsonArrayLike.plus(value: Nothing?): JsonArrayLike {
62+
operator fun JsonArrayLike.plus(value: Nothing?): JsonArray {
6363
val element = JsonNull
64-
return this + element
64+
return JsonArray(this + element)
6565
}
6666

6767
//
6868

6969
/** return the combination of [this] excluding the first element equivalent to [value] */
70-
operator fun JsonArrayLike.minus(value: JsonObjectLike?): JsonArrayLike {
70+
operator fun JsonArrayLike.minus(value: JsonObjectLike?): JsonArray {
7171
val element = value?.toJsonObject().orJsonNull()
72-
return this - element
72+
return JsonArray(this - element)
7373
}
7474

7575
/** return the combination of [this] excluding the first element equivalent to [value] */
76-
operator fun JsonArrayLike.minus(value: JsonArrayLike?): JsonArrayLike {
76+
operator fun JsonArrayLike.minus(value: JsonArrayLike?): JsonArray {
7777
val element = value?.toJsonArray().orJsonNull()
78-
return this - element
78+
return JsonArray(this - element)
7979
}
8080

8181
/** return the combination of [this] excluding the first element equivalent to [value] */
82-
operator fun JsonArrayLike.minus(value: String?): JsonArrayLike {
82+
operator fun JsonArrayLike.minus(value: String?): JsonArray {
8383
val element = JsonPrimitive(value)
84-
return this - element
84+
return JsonArray(this - element)
8585
}
8686

8787
/** return the combination of [this] excluding the first element equivalent to [value] */
88-
operator fun JsonArrayLike.minus(value: Number?): JsonArrayLike {
88+
operator fun JsonArrayLike.minus(value: Number?): JsonArray {
8989
val element = JsonPrimitive(value)
90-
return this - element
90+
return JsonArray(this - element)
9191
}
9292

9393
/** return the combination of [this] excluding the first element equivalent to [value] */
94-
operator fun JsonArrayLike.minus(value: Boolean?): JsonArrayLike {
94+
operator fun JsonArrayLike.minus(value: Boolean?): JsonArray {
9595
val element = JsonPrimitive(value)
96-
return this - element
96+
return JsonArray(this - element)
9797
}
9898

9999
/** return the combination of [this] excluding the first element equivalent to [value] */
100-
operator fun JsonArrayLike.minus(value: Nothing?): JsonArrayLike {
100+
operator fun JsonArrayLike.minus(value: Nothing?): JsonArray {
101101
val element = JsonNull
102-
return this - element
102+
return JsonArray(this - element)
103103
}
104104

105105
//

module-extkt-json/src/commonMain/kotlin/JsonObjectLike.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,50 +31,50 @@ fun JsonObjectLike.copy(block: MutableJsonObjectLike.() -> Unit): JsonObject {
3131

3232
/** return the combination of [this] and the given key-value [pair] */
3333
@JvmName("plusStringMapPair")
34-
operator fun JsonObjectLike.plus(pair: Pair<String, JsonObjectLike?>): JsonObjectLike {
34+
operator fun JsonObjectLike.plus(pair: Pair<String, JsonObjectLike?>): JsonObject {
3535
val (name, value) = pair
3636
val element = value?.toJsonObject().orJsonNull()
37-
return this + (name to element)
37+
return JsonObject(this + (name to element))
3838
}
3939

4040
/** return the combination of [this] and the given key-value [pair] */
4141
@JvmName("plusStringListPair")
42-
operator fun JsonObjectLike.plus(pair: Pair<String, JsonArrayLike?>): JsonObjectLike {
42+
operator fun JsonObjectLike.plus(pair: Pair<String, JsonArrayLike?>): JsonObject {
4343
val (name, value) = pair
4444
val element = value?.toJsonArray().orJsonNull()
45-
return this + (name to element)
45+
return JsonObject(this + (name to element))
4646
}
4747

4848
/** return the combination of [this] and the given key-value [pair] */
4949
@JvmName("plusStringStringPair")
50-
operator fun JsonObjectLike.plus(pair: Pair<String, String?>): JsonObjectLike {
50+
operator fun JsonObjectLike.plus(pair: Pair<String, String?>): JsonObject {
5151
val (name, value) = pair
5252
val element = JsonPrimitive(value)
53-
return this + (name to element)
53+
return JsonObject(this + (name to element))
5454
}
5555

5656
/** return the combination of [this] and the given key-value [pair] */
5757
@JvmName("plusStringNumberPair")
58-
operator fun JsonObjectLike.plus(pair: Pair<String, Number?>): JsonObjectLike {
58+
operator fun JsonObjectLike.plus(pair: Pair<String, Number?>): JsonObject {
5959
val (name, value) = pair
6060
val element = JsonPrimitive(value)
61-
return this + (name to element)
61+
return JsonObject(this + (name to element))
6262
}
6363

6464
/** return the combination of [this] and the given key-value [pair] */
6565
@JvmName("plusStringBooleanPair")
66-
operator fun JsonObjectLike.plus(pair: Pair<String, Boolean?>): JsonObjectLike {
66+
operator fun JsonObjectLike.plus(pair: Pair<String, Boolean?>): JsonObject {
6767
val (name, value) = pair
6868
val element = JsonPrimitive(value)
69-
return this + (name to element)
69+
return JsonObject(this + (name to element))
7070
}
7171

7272
/** return the combination of [this] and the given key-value [pair] */
7373
@JvmName("plusStringNothingPair")
74-
operator fun JsonObjectLike.plus(pair: Pair<String, Nothing?>): JsonObjectLike {
74+
operator fun JsonObjectLike.plus(pair: Pair<String, Nothing?>): JsonObject {
7575
val (name, _) = pair
7676
val element = JsonNull
77-
return this + (name to element)
77+
return JsonObject(this + (name to element))
7878
}
7979

8080
//

0 commit comments

Comments
 (0)