vertx-lang-kotlin icon indicating copy to clipboard operation
vertx-lang-kotlin copied to clipboard

Erroneous code example in docs

Open joachimnielandt opened this issue 6 years ago • 1 comments

The following code on this page seems to be broken (I guess it was intended to contain a obj function call):

// The json builder declares a JSON structure
val result = json {
  "firstName" to "Dale",
  "lastName" to "Cooper",
  "age" to 64,
  "names" to array("Dale", "Bartholomew")
}

On another note, the example

// The json builder declares a JSON structure
val result = json {

  // in this structure the array function can be used

  // takes a vararg of values
  array("1", "2", "3")

  // or an iterable of values
  array((1..3).map { "$it" })

  // apply function on array receiver
  array {
    for (i in 1..3) {
      add("$i")
    }
  }
}

is slightly confusing to me, as it is not clear that only the last array{} function will actually have an impact on the json builder. As a kotlin beginner, I expected the result of the json builder to be ["1","2","3","1","2","3","1","2","3"], instead of ["1","2","3"]. Is this correct?

joachimnielandt avatar Jul 30 '18 08:07 joachimnielandt

I think are example is indeed misleading it should be like this https://github.com/vert-x3/vertx-lang-kotlin/blob/3.5/vertx-lang-kotlin/src/test/kotlin/io/vertx/lang/kotlin/test/JsonTest.kt#L82 for the last one

vietj avatar Jul 30 '18 12:07 vietj