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

Initial sketch of optics module #78

Merged
merged 5 commits into from Nov 25, 2015

Conversation

Projects
None yet
4 participants
@travisbrown
Member

travisbrown commented Oct 29, 2015

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.

@codecov-io

This comment has been minimized.

Show comment
Hide comment
@codecov-io

codecov-io Oct 29, 2015

Current coverage is 75.10%

Merging #78 into master will increase coverage by +1.93% as of 7df3639

Powered by Codecov. Updated on successful CI builds.

codecov-io commented Oct 29, 2015

Current coverage is 75.10%

Merging #78 into master will increase coverage by +1.93% as of 7df3639

Powered by Codecov. Updated on successful CI builds.

@travisbrown

This comment has been minimized.

Show comment
Hide comment
@travisbrown

travisbrown Oct 30, 2015

Member

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
        }
      }
    ]
  }
}
Member

travisbrown commented Oct 30, 2015

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
        }
      }
    ]
  }
}

@travisbrown travisbrown added this to the 0.3.0 milestone Nov 5, 2015

@travisbrown travisbrown referenced this pull request Nov 5, 2015

Closed

Monocle lenses for Circe #39

@julien-truffaut

This comment has been minimized.

Show comment
Hide comment
@julien-truffaut

julien-truffaut Nov 23, 2015

Contributor

You can upgrade monocle to 1.2.0-M2 and define a Plated instance

Contributor

julien-truffaut commented Nov 23, 2015

You can upgrade monocle to 1.2.0-M2 and define a Plated instance

@travisbrown

This comment has been minimized.

Show comment
Hide comment
@travisbrown

travisbrown Nov 24, 2015

Member

I'm going to merge this when it's green on the understanding that the JsonPath API is subject to change.

Member

travisbrown commented Nov 24, 2015

I'm going to merge this when it's green on the understanding that the JsonPath API is subject to change.

travisbrown added a commit that referenced this pull request Nov 25, 2015

@travisbrown travisbrown merged commit 81a9206 into master Nov 25, 2015

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@travisbrown travisbrown deleted the topic/optics branch Nov 30, 2015

@dwijnand

This comment has been minimized.

Show comment
Hide comment
@dwijnand

dwijnand Jan 27, 2016

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.

Contributor

dwijnand commented Jan 27, 2016

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.

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