helios icon indicating copy to clipboard operation
helios copied to clipboard

Weird 'add' function

Open ambrusadrianzh opened this issue 5 years ago • 3 comments

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.

ambrusadrianzh avatar Sep 09 '19 12:09 ambrusadrianzh

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)

nomisRev avatar Sep 09 '19 17:09 nomisRev

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))

lostintime avatar Oct 09 '19 12:10 lostintime

Yes, that's definitely the expected behavior of add.

nomisRev avatar Oct 09 '19 12:10 nomisRev