JsonObject and especially JsonArray would be good candidates to enrich with monad (map, flatMap, filter) and higer-order functions (forall, etc.). As they are Java types at the moment, it needs some nasty conversions into equivalent Scala collections to get there.
Looping over a JsonArray looks like this at the moment:
val items: JsonArray = someFunction()
for (index <- 0 until items.size()) yield items.get[JsonObject](index).get("someKey")
But what i would love to see for JsonArray is:
val items: JsonArray[JsonObject] = someFunction()
// for expression
for (item <- items) yield item.get[Integer]("someKey")
// map
items.map(item => item.get[Integer]("someKey"))
// filter
items.filter(item => item.get[Integer]("someKey") > 5)
The same makes sense for JsonObject, even though JsonArray is the more natural candidate here.
JsonObject and especially JsonArray would be good candidates to enrich with monad (map, flatMap, filter) and higer-order functions (forall, etc.). As they are Java types at the moment, it needs some nasty conversions into equivalent Scala collections to get there.
Looping over a JsonArray looks like this at the moment:
But what i would love to see for JsonArray is:
The same makes sense for JsonObject, even though JsonArray is the more natural candidate here.