helios
helios copied to clipboard
Weird 'add' function
Currently the add function looks like this:
fun add(key: String, value: Json): JsObject = JsObject(hashMapOf(key to value))
It's a bit confusing. Is it intentional? Maybe as an of
it would be clearer.
I agree, it's not intentional but we've not added any sugar constructors or not many.
We should add:
data class JsObject(...): Json() {
companion object {
operator fun invoke(vararg: Pair<String, Json>): JsObject = ...
}
}
Which would allow following syntax: JsObject(key to value)
IMO expected behavior for add
method would be to add new object field to called instance:
fun add(key: String, value: Json): JsObject = JsObject(this.value + hashMapOf(key to value))
Yes, that's definitely the expected behavior of add
.