Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 29 16:59
    rpiaggio opened #1293
  • Jul 27 03:37

    julien-truffaut on gh-pages

    Deploy website Deploy website … (compare)

  • Jul 27 03:32

    xuwei-k on master

    Update sbt-mdoc to 2.3.3 (#1292) (compare)

  • Jul 27 03:32
    xuwei-k closed #1292
  • Jul 27 03:27
    xuwei-k auto_merge_enabled #1292
  • Jul 27 03:25
    scala-steward-bot synchronize #1292
  • Jul 27 00:00
    scala-steward-bot synchronize #1292
  • Jul 26 23:01
    scala-steward-bot synchronize #1292
  • Jul 26 22:03
    scala-steward-bot synchronize #1292
  • Jul 26 21:01
    scala-steward-bot synchronize #1292
  • Jul 26 20:01
    scala-steward-bot synchronize #1292
  • Jul 26 19:14
    scala-steward-bot synchronize #1292
  • Jul 26 18:02
    scala-steward-bot synchronize #1292
  • Jul 26 17:23
    scala-steward-bot review_requested #1292
  • Jul 26 17:23
    scala-steward-bot review_requested #1292
  • Jul 26 17:23
    scala-steward-bot review_requested #1292
  • Jul 26 17:23
    scala-steward-bot opened #1292
  • Jul 12 05:21

    julien-truffaut on gh-pages

    Deploy website Deploy website … (compare)

  • Jul 12 05:15

    xuwei-k on master

    Update sbt to 1.7.1 (compare)

  • Jul 12 05:15
    xuwei-k closed #1291
Bob Glamm
@glamm
cool. For now I can define my indexed lenses in a separate compilation unit. Thanks!
Julien Truffaut
@julien-truffaut
you can use this workaround for now import cats.syntax.all.{index => _}
Bob Glamm
@glamm
Ahh, that also works for me I'm pretty sure. Thanks again!
bblfish
@bblfish:matrix.org
[m]
Hi, this I have put some ideas together on web-cats/CG#28. They are more on the theoretical side I think for the moment, but could be quite interesting.
I am working on a little demo using Monocle to see if that can give some insight into what a web server is.
bblfish
@bblfish:matrix.org
[m]
As I am modelling a Web Server as a nested HashMap, where the path of keys form the path of the URL. It is easy to write a getter using fold on the path, but I don't think it is so easy to build a setter. I would need a lens for a recursive datastructure. But looking around it seems that is not available.
bblfish
@bblfish:matrix.org
[m]
I guess that is equivalent to a tree with the path leading to a node where data lies.
bblfish
@bblfish:matrix.org
[m]
From what I gather searching the web, what is needed is what in Haskell is called Plated https://qfpl.io/posts/optimising-free-with-plated/
Julien Truffaut
@julien-truffaut
There is a Plated typeclass in Monocle too
bblfish
@bblfish:matrix.org
[m]
Ah! I saw some stackexchange questions which said that that was not there. Found it.
bblfish
@bblfish:matrix.org
[m]
I am not sure Plated is what I was looking for. I was looking for a way to locate a node in a Tree by a path, so that I could see what was there or change it.
Gabriel Volpe
@gvolpe:matrix.org
[m]
Maybe that's just Traversal ? bblfish
bblfish
@bblfish:matrix.org
[m]

going by the doc on traversal

A Traversal is the generalisation of an Optional to several targets. In other word, a Traversal allows to focus from a type S into 0 to n values of type A.

I guess that the usual path to an element is defined statically in the Monocle Lenses, whereas what is needed here is a path that is specified at run time.
Ken Scambler
@kenbot
Indexes let you do that. Looking at the Resource/Container structure that you/Henry Story submitted, you should be able to define given Index instances for your types, then do something like root.focus(_.index("www").index("foo").index("com").index("index.html").content).get
bblfish
@bblfish:matrix.org
[m]
sh ok, so I should be able to fold on a list to create such an index.
I'll try that.
Ken Scambler
@kenbot
You need to suck in a typeclass instance for each index call, so folding on a list of strings might not work in a straightforward way
bblfish
@bblfish:matrix.org
[m]

I think all I need is a way to be able to pick leaves of a

type Tree[+A] = Free[Map[String,_], A]

by the path to it's leaves... (need to think if that is the right datastructure first)

bblfish
@bblfish:matrix.org
[m]

:point_up: Edit: I think all I need is a way to be able to pick leaves of a

type Indexed[R] = Map[String,R]
type DirTree[A] =  Free[Indexed, A]

by the path to it's leaves... (need to think if that is the right datastructure first)

bblfish
@bblfish:matrix.org
[m]
No, I don't think that works...
Julien Truffaut
@julien-truffaut
Monocle 3.1.0 is released with a new refocus operation and better compatibility with cats.
bblfish
@bblfish:matrix.org
[m]
not on maven central yet though https://repo1.maven.org/maven2/dev/optics/
Ken Scambler
@kenbot
Hey @bblfish:matrix.org, could you maybe write some "fantasy code" showing what you're trying to do, if you could magic the right functionality into existence?
bblfish
@bblfish:matrix.org
[m]
I think I have something that works. I'll put it on github, and send a link here.
I was really here trying to use Monocle as a tool to quickly get an idea of how a web server could be seen as a Lens, more for theoretical purposes. (to understand what GET, PUT, POST, etc... are).
bblfish
@bblfish:matrix.org
[m]
@kenbot: I wrote together a little "web server" using lenses :-)
https://github.com/bblfish/lens-play/blob/master/src/main/scala/server/Server.scala
definitely very fantasy :-)
I have a feeling that the recent work on the category of polynomials allows one to think of actor systems as generalised lenses.... But I have no confirmation of that yet, and it's a lot of work to work out.
bblfish
@bblfish:matrix.org
[m]
But you will see there that I had to use Index to take a list to find the right element to replace in the web server.
bblfish
@bblfish:matrix.org
[m]
For a bit of context see web-cats/CG#28
Julien Truffaut
@julien-truffaut
There is a Monocle chanel in the typelevel discord server. We'll most likely phase out gitter over the next few weeks: https://discord.com/invite/XF3CXcMzqD
Ken Scambler
@kenbot
I've given you some detailed feedback over on Typelevel discord, @bblfish:matrix.org
Joan Goyeau
@joan38

Hey!
I have:

sealed trait T {
  def yo: String
}
case class B(yo: String)
case class C(yo: String, ya: Int)

How can I do something like:

val all: Seq[T] = ???
all.map(_.lens(_.yo).set("blabla"))

?
It gives me Cannot find method yo in T

Joan Goyeau
@joan38
I think my usecase has no solution: optics-dev/Monocle#363
ritschwumm
@ritschwumm

@joan38 i tend to model these things like

case class Yoing(yo:String, t:T)
sealed trait T
case object B extends T
case class C(ya:Int) extends T

to make it clear to the reader the "yo" plays the same role.
incidentally, that would solve your problem, too

Jens Grassel
@jan0sch
Hi, is there a way to make Focus or GenLens work on overloaded methods?
I am using Monocle 3.1 on Scala 3.1 and if I try to either use .focus(_.foo) or GenLens[T](_.foo) I get an error that Select.unique is not supported for overloaded methods. I did fiddle around with something like f.focus().andThen(_.foo) which at least compiles but that doesn't seem to be the right direction.
Artem Egorkine
@arteme
case class Outer(
  inner: Option[Inner]
)

case class Inner(
  str: String
)

val p = GenLens[Outer](_.inner) composePrism some
val zero = Outer(inner = None)

val n = p.set(Inner("hello"))(zero)
Why do I get Outer(inner = None)? Shouldn't the some prism be setting inner correctly?
1 reply
Artem Egorkine
@arteme
there's nothing wrong with the prism, but the resulting optional always confuses me -- I often need a setter
A setter for deep nesting like this:
  private def definingOptional[T](empty: => T) = Optional[Option[T], T] {
    case Some(v) => Some(v)
    case None => Some(empty)
  }(v => _ => Some(v))
Kaspar Minosiants
@minosiants
Hello guys.
Is there way to use a Monocle latest version with scala 2.11 or only a Monocle 1.6.x version should be used ?
2 replies
Swoorup Joshi
@Swoorup
is there a way to update 2 fields at the same time?
Naftoli Gugenheim
@nafg
@Swoorup you can write a lens that returns a tuple
Ghost
@ghost~60575c976da037398474972a

Hey guys, i'm kinda confused with a task my prof gave us hopefully one of oyu could help me out ^^
We've got a "database" with dummy values and we need to inspect/get and modify some of the values depending on who requested them
object Database extends Database:
private var data: Map[InsuranceNumber,Item] = Map(
120971233 -> Item(
InsuranceKind.Public,
Name("Ali","Meyer"),
Date(13,Month.Aug,1987),
Address("Karlstraße","1a","D-12849","Wannstadt"),
Seq(TelephoneNo(true,"+49 127 12039123")),
Seq("Excessive Gaming","Flu"),
Date(5, Month.Sep, 2022)
),
12309812 -> Item(
InsuranceKind.Private,
Name("Olga", "Lee"),
Date(12, Month.Mar, 2001),
Address("Blumenweg","14","D-28209","Bremen"),
Seq(TelephoneNo(true,"+49 421 12039812"), TelephoneNo(false,"+49 177 102931823")),
Seq("Covid"),
Date(4, Month.Aug, 2022)
),

So if a patient requests the data, he needs to authenticate using the insurance number and his data of birth
def queryA: A
def updateA(f: A => A): Unit

These two functions should be used to update and retrieve the values but i'm legit stuck at how to approach this problem

felher
@felher

Hey all, is there an easy way to zoom into a list by predicate and modify all elements that satisfy the predicate?

Something like List(1, 2, 3, 4).focus(_.filter(_ < 3).modify(_ * 2) leading to List(2, 4, 3, 4)

felher
@felher
Okay, in my real code I now have
this.focus(_.simulations).each.filter(_.id == id).modify(_.focus(_.config).replace(nc))
but I wonder if the double-focus is necessary or if there is a way to write it more like
this.focus(_.simulations.filter(_.id == id).each.config).replace(nc)
Felix Bjært Hargreaves
@hejfelix
List( (1,2), (3,4) ) how do I modify the 2nd parameter of each tuple? I can't seem to find the tuple lenses in the docs
1 reply