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

JsonObject and JsonArray should have (Scala) monad and higher-order functions #170

Open
christian-bick opened this issue Aug 6, 2014 · 1 comment

Comments

@christian-bick
Copy link

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.

@galderz
Copy link
Contributor

galderz commented Sep 11, 2014

Yeah, very valid points. We didn't get around to doing it for 1.x. We hope to improve on it for 2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants