diff options
author | Johannes Rudolph <johannes_rudolph@gmx.de> | 2012-05-30 17:21:28 +0200 |
---|---|---|
committer | Johannes Rudolph <johannes_rudolph@gmx.de> | 2012-05-30 17:21:28 +0200 |
commit | 9dd9dfb91ff353ceb491d13accf5f5d8502e6496 (patch) | |
tree | 9a6cf5168550bfc8dada3348b6ca9e6e7f3f82b0 | |
parent | e067ba4efd5f8b87cc57a34a58c7575b128bb8ec (diff) | |
download | spray-json-9dd9dfb91ff353ceb491d13accf5f5d8502e6496.tar.gz spray-json-9dd9dfb91ff353ceb491d13accf5f5d8502e6496.tar.bz2 spray-json-9dd9dfb91ff353ceb491d13accf5f5d8502e6496.zip |
`*` now an alias for `elements`
-rw-r--r-- | src/main/scala/cc/spray/json/JsonLenses.scala | 6 | ||||
-rw-r--r-- | src/test/scala/cc/spray/json/JsonPathTests.scala | 2 |
2 files changed, 6 insertions, 2 deletions
diff --git a/src/main/scala/cc/spray/json/JsonLenses.scala b/src/main/scala/cc/spray/json/JsonLenses.scala index d7f8f6f..c1765a3 100644 --- a/src/main/scala/cc/spray/json/JsonLenses.scala +++ b/src/main/scala/cc/spray/json/JsonLenses.scala @@ -253,7 +253,7 @@ object JsonLenses { def retr: JsValue => SafeJsValue = x => Right(x) } - def elements: SeqProjection = new Proj[Seq] { + val elements: SeqProjection = new Proj[Seq] { def updated(f: SafeJsValue => SafeJsValue)(parent: JsValue): SafeJsValue = parent match { case JsArray(elements) => ops.allRight(elements.map(x => f(Right(x)))).map(JsArray(_: _*)) @@ -265,6 +265,10 @@ object JsonLenses { case e@_ => unexpected("Not a json array: "+e) } } + + /** Alias for `elements` */ + def * = elements + def filter(pred: JsPred): SeqProjection = new Proj[Seq] { def updated(f: SafeJsValue => SafeJsValue)(parent: JsValue): SafeJsValue = parent match { //case JsArray(elements) => diff --git a/src/test/scala/cc/spray/json/JsonPathTests.scala b/src/test/scala/cc/spray/json/JsonPathTests.scala index 8ba75bd..6347002 100644 --- a/src/test/scala/cc/spray/json/JsonPathTests.scala +++ b/src/test/scala/cc/spray/json/JsonPathTests.scala @@ -37,7 +37,7 @@ class JsonPathTests extends Specification with SpecHelpers { "Examples" should { "All authors" in { - json extract ("store" / "book" / elements / "author").get[String] must be_==(Seq("Nigel Rees", "Evelyn Waugh")) + json extract ("store" / "book" / * / "author").get[String] must be_==(Seq("Nigel Rees", "Evelyn Waugh")) } "Author of first book" in { json extract ("store" / "book" / element(0) / "author").get[String] must be_==("Nigel Rees") |