Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 27 21:09

    julien-truffaut on gh-pages

    Deploy website Deploy website … (compare)

  • Sep 27 21:03

    xuwei-k on master

    Update sbt-mdoc to 2.3.5 (#1302) (compare)

  • Sep 27 21:03
    xuwei-k closed #1302
  • Sep 27 20:01
    scala-steward-bot synchronize #1302
  • Sep 27 19:18
    scala-steward-bot synchronize #1302
  • Sep 27 18:16
    scala-steward-bot synchronize #1302
  • Sep 27 17:28
    scala-steward-bot review_requested #1302
  • Sep 27 17:28
    scala-steward-bot review_requested #1302
  • Sep 27 17:28
    scala-steward-bot review_requested #1302
  • Sep 27 17:28
    scala-steward-bot opened #1302
  • Sep 26 07:02
    julien-truffaut commented #1301
  • Sep 26 00:19
    kubukoz opened #1301
  • Sep 23 22:35

    julien-truffaut on gh-pages

    Deploy website Deploy website … (compare)

  • Sep 23 22:28

    xuwei-k on master

    Update sbt-mdoc to 2.3.4 (#1300) (compare)

  • Sep 23 22:28
    xuwei-k closed #1300
  • Sep 23 22:02
    scala-steward-bot synchronize #1300
  • Sep 23 21:08
    scala-steward-bot synchronize #1300
  • Sep 23 19:59
    scala-steward-bot synchronize #1300
  • Sep 23 19:14
    scala-steward-bot synchronize #1300
  • Sep 23 18:17
    scala-steward-bot synchronize #1300
Julien Truffaut
@julien-truffaut
The rest we can improve over time.
I was hoping to have time to work on the documentation but my online course takes my full attention until August :(
Julien Truffaut
@julien-truffaut
We also need a Scala 3 version of this feature.
Naftoli Gugenheim
@nafg
Is @Lenses supposed to work on 2.13.6? Something broke, not sure why
Julien Truffaut
@julien-truffaut
@nafg it is not expected but there seems to be other macro issues with 2.13.6
Julien Truffaut
@julien-truffaut
I released 3.0.0-M6 yesterday for Scala 3 but I don't see it Maven central https://search.maven.org/search?q=monocle-core
Naftoli Gugenheim
@nafg
@julien-truffaut are you sure releasing completed successfully?
Julien Truffaut
@julien-truffaut
No, I mean the pipeline was successful: optics-dev/Monocle@5849596
butthere might be an issue somewhere else
So it seems M6 artifacts were created
Carlos Quiroz
@cquiroz
I managed to update so at least someting was publised
But I don't see any _3 artifacts
Maybe the search site indexes aren't updated
Actually if I type into the address bar directly there is _3 too: https://repo1.maven.org/maven2/com/github/julien-truffaut/monocle-core_3/
So it seems like the directory page https://repo1.maven.org/maven2/com/github/julien-truffaut/ hasn't been updated
@julien-truffaut I guess it's all there but eventual consistency at play
Has anyone got @Lenses working on 2.13.6?
2.1.0
Tanay Taneja
@TanayTaneja_twitter

Hi, newbie here!
I am trying to use Monocle, but both
import monocle.Focus AND import monocle.macros.syntax.all._
say they cant resolve symbol Focus, and 'all' respectively.

What am I missing out here ?

Julien Truffaut
@julien-truffaut
Which version of Monocle are you using?
Tanay Taneja
@TanayTaneja_twitter
2.1.0
Julien Truffaut
@julien-truffaut
that's why, it is only in the 3.0.0 milestone
Naftoli Gugenheim
@nafg
Tested on scastie, @Lenses works on 2.13.6
So idk why it stops working when I set my project to 2.13.6 rather than 2.13.5, at least in one particular file
Julien Truffaut
@julien-truffaut
any objection to make 3.0.0-M6, the first RC? Originally, I wanted to .field (optics-dev/Monocle#1125) but it can be added later
Carlos Quiroz
@cquiroz
👍
Tanay Taneja
@TanayTaneja_twitter

I am trying to create a lens, which accesses different fields in a case class, eg: GenLens[Person](_.details.age) , GenLens[Person](_.details.address) , GenLens[Person](_.details.name)

Is there a way I can do this by generalizing the changing field? Something like

val attribute = "name"
GenLens[Person](_.details.$attribute)
Julien Truffaut
@julien-truffaut
You can generate a Lens[Person, Details] and then compose it with GenLens[Details](_.age) or GenLens[Details](_.address)
not shorter though
Tanay Taneja
@TanayTaneja_twitter
I see :/
@julien-truffaut The above lens is part of a few more changes, I was wondering if I could pack it all inside a function, because the only difference there is in that genlens piece, do you have any suggestions on what could be a better way to do it?
Julien Truffaut
@julien-truffaut
not really, either you break it down in small pieces and you compose the optics or you generate the whole optic using macro like focus in Scala 3
fromscalatohaskell
@fromscalatohaskell_gitlab

I'm really stuck on something ... I'm trying to generate at runtime list of lenses to modify a data structure... here's simplified example:

  sealed trait TreeLike
  final case class Tree(id: String, leaves: List[Leaf]) extends TreeLike
  final case class Leaf(i: Int) extends TreeLike

  val tree = Tree(
    "t1", List(Leaf(1), Leaf(2), Leaf(3))
  )

  val treeLens = tree.focus()

  val lenses: List[AppliedLens[Tree, Leaf]] = ??? // list of lenses for leaves where i%2 ==0

how would I go about this? Where I essentially need to fold over runtime values to make lenses
btw kickass library

fromscalatohaskell
@fromscalatohaskell_gitlab
this seems to work, is it "correct" ?
  sealed trait TreeLike
  final case class Tree(id: String, leaves: List[Leaf]) extends TreeLike
  final case class Leaf(num: Int) extends TreeLike

  val tree = Tree(
    "t1", List(Leaf(1), Leaf(2), Leaf(3), Leaf(4))
  )

  val lenses: List[Traversal[Tree, Leaf]] =
    tree.leaves.map {
      x =>
        if (x.num % 2 == 0) {
          val ff = Focus[Tree](_.leaves)
            .andThen(Traversal.fromTraverse[List, Leaf])
            .andThen(
              Prism[Leaf, Leaf] { bi =>
                if (bi == x) Some(bi)
                else None
              }(identity)
            )
          Some(ff)
        } else None
    }.collect { case Some(x) => x }

  val res = lenses.foldLeft(tree) { case (t, lens) =>
    lens.modify(x => Leaf(x.num + 10))(t)
  }
Naftoli Gugenheim
@nafg
best way to know is to test it ;)
Julien Truffaut
@julien-truffaut
It seems that you could use a Traversal (optics that targets many values of the same type), Plated might also be an option, it deals with recursive data structures like your Tree https://github.com/optics-dev/Monocle/blob/master/example/src/test/scala/monocle/JsonExample.scala#L227-L259
fromscalatohaskell
@fromscalatohaskell_gitlab
I use traversal, it's more of a how to decide if we want lens for this field at runtime
the above works but it's weird that inside Prism I check if it's equal to thing the outside map is introducing
the above code would increment Leaf(2) and Leaf(4) because they %2...
but I wonder if there's better way... <== optics noob
Julien Truffaut
@julien-truffaut
if you use the latest version of Monocle, you can use .filter instead of a custom Prism
fromscalatohaskell
@fromscalatohaskell_gitlab
thanks!!! thats a bit nicer
any other tips?
Julien Truffaut
@julien-truffaut
I am not sure why you start with tree.leaves.map {
fromscalatohaskell
@fromscalatohaskell_gitlab
I need to return list of setters for parts of subtree essentially
Julien Truffaut
@julien-truffaut
It seems you could do
Focus[Tree](_.leaves).filter(_.num % 2 == 0)
fromscalatohaskell
@fromscalatohaskell_gitlab
in my real app i have analyser that checks it against some outside rules and returns List(Rule, Setter)
Julien Truffaut
@julien-truffaut
k