Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 04 13:46

    julien-truffaut on gh-pages

    Deploy website Deploy website … (compare)

  • Oct 04 13:38

    xuwei-k on master

    Update sbt-mdoc to 2.3.6 (#1304) (compare)

  • Oct 04 13:38
    xuwei-k closed #1304
  • Oct 04 12:02
    scala-steward-bot synchronize #1304
  • Oct 04 11:10
    scala-steward-bot synchronize #1304
  • Oct 04 10:14
    scala-steward-bot synchronize #1304
  • Oct 04 09:16
    scala-steward-bot review_requested #1304
  • Oct 04 09:16
    scala-steward-bot review_requested #1304
  • Oct 04 09:16
    scala-steward-bot review_requested #1304
  • Oct 04 09:16
    scala-steward-bot opened #1304
  • Oct 03 11:12

    julien-truffaut on gh-pages

    Deploy website Deploy website … (compare)

  • Oct 03 11:05

    xuwei-k on master

    Update sbt to 1.7.2 (compare)

  • Oct 03 11:05
    xuwei-k closed #1303
  • Oct 03 10:13
    scala-steward-bot synchronize #1303
  • Oct 03 09:17
    scala-steward-bot synchronize #1303
  • Oct 03 08:09
    scala-steward-bot synchronize #1303
  • Oct 03 07:31
    scala-steward-bot synchronize #1303
  • Oct 03 06:24
    scala-steward-bot synchronize #1303
  • Oct 03 04:50
    scala-steward-bot review_requested #1303
  • Oct 03 04:50
    scala-steward-bot review_requested #1303
Jakub Kozłowski
@kubukoz:matrix.org
[m]
which is understandable
Julien Truffaut
@julien-truffaut
At the moment, all Scala 3 macro generate normal optics (non polymoprhic)
@kenbot has some genius plan for polymorphic ones but it will probably take some time.
Carlos Quiroz
@cquiroz
Now that scala 3 is out how far form Monocle 3 are we?
Julien Truffaut
@julien-truffaut
ahah a tough question!
Code wise, it is mostly ready. All the big changes are there except optics-dev/Monocle#1125
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