Merged
Conversation
597bed0 to
657bc22
Compare
Current coverage is
|
Member
Author
|
Example usage: import cats.data.Xor
import io.circe._, generic.auto._, jawn._, optics._
import monocle.macros.Lenses
@Lenses case class Foo(count: Int)
@Lenses case class Qux(foo: Foo, s: String)
val toQux = JsonPath.root.x.y.at(2).as[Qux]
val incrementCount = toQux.composeLens(Qux.foo).composeLens(Foo.count).modify(_ + 1)
val Xor.Right(json) = parse("""
{ "x" : { "y" : [0, 1, { "foo" : { "count" : 3 }, "s" : "abcde" }] } }
""")And then: scala> json
res0: io.circe.Json =
{
"x" : {
"y" : [
0,
1,
{
"foo" : {
"count" : 3
},
"s" : "abcde"
}
]
}
}
scala> incrementCount(json)
res1: io.circe.Json =
{
"x" : {
"y" : [
0,
1,
{
"s" : "abcde",
"foo" : {
"count" : 4
}
}
]
}
} |
Contributor
There was a problem hiding this comment.
I believe that as is not lawful because decoder is not injective e.g.
case class Point(x: Int, y: Int)
val decoder: Decoder[Point] = ...
decoder.decodeJson(obj("x" -> int(1), "y" -> int(2))) == decoder.decodeJson(obj("x" -> int(1), "y" -> int(2), "z" -> int(5))) 9439c35 to
2ee2da9
Compare
2ee2da9 to
800782e
Compare
Closed
800782e to
577023f
Compare
Contributor
|
You can upgrade monocle to 1.2.0-M2 and define a |
6dbb713 to
dab1cc3
Compare
dab1cc3 to
6f18c78
Compare
Member
Author
|
I'm going to merge this when it's green on the understanding that the |
travisbrown
added a commit
that referenced
this pull request
Nov 25, 2015
Initial sketch of optics module
Contributor
|
The readme brought me here ("We are likely to add an experimental optics subproject in 0.3.0"), so given this is merged I think the readme should be updated. |
julienrf
pushed a commit
to scalacenter/circe
that referenced
this pull request
May 13, 2021
Don't define charBuilder where it's unneeded
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a partial port from Argonaut in response to #39 and this question. If we can get some docs and tests in place before Shapeless 2.3.0 is out, I'd be happy to publish this with 0.2.0, but I don't want to wait for it.