Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird 'add' function #118

Open
ambrusadrianzh opened this issue Sep 9, 2019 · 3 comments · May be fixed by #129
Open

Weird 'add' function #118

ambrusadrianzh opened this issue Sep 9, 2019 · 3 comments · May be fixed by #129
Labels

Comments

@ambrusadrianzh
Copy link

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.

@nomisRev
Copy link
Contributor

nomisRev commented Sep 9, 2019

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)

@lostintime
Copy link

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

@nomisRev
Copy link
Contributor

nomisRev commented Oct 9, 2019

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

@ambrusadrianzh ambrusadrianzh linked a pull request Oct 22, 2019 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants