Pre-SIP: A Syntax for Collection Literals

Also the motivating example here by @lihaoyi

val json0 = ujson.Arr(
  ujson.Obj("myFieldA" -> ujson.Num(1), "myFieldB" -> ujson.Str("g")),
  ujson.Obj("myFieldA" -> ujson.Num(2), "myFieldB" -> ujson.Str("k"))
)

could be made concise and more readable by a simple import:

import ujson.*
val json0 = Arr(
  Obj("myFieldA" -> Num(1), "myFieldB" -> Str("g")),
  Obj("myFieldA" -> Num(2), "myFieldB" -> Str("k")),
)

and I think that there are readability and safety benefits in having Obj, Num, Str written explicitly, compared to a bracket salad.

10 Likes