Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 15:17

    julien-truffaut on gh-pages

    Deploy website Deploy website … (compare)

  • 15:11

    cquiroz on master

    Update sbt-scalafmt to 2.4.5 Merge pull request #1236 from s… (compare)

  • 15:11
    cquiroz closed #1236
  • 04:35
    scala-steward opened #1236
  • Dec 03 12:27

    julien-truffaut on gh-pages

    Deploy website Deploy website … (compare)

  • Dec 03 12:22

    xuwei-k on master

    Update index.js (#1234) * Upda… (compare)

  • Dec 03 12:22
    xuwei-k closed #1234
  • Dec 03 12:22
    xuwei-k closed #1229
  • Dec 03 12:15
    xuwei-k auto_merge_enabled #1234
  • Dec 03 12:15
    xuwei-k synchronize #1234
  • Dec 03 12:15
    xuwei-k synchronize #1234
  • Dec 03 11:59

    julien-truffaut on gh-pages

    Deploy website Deploy website … (compare)

  • Dec 03 11:53

    cquiroz on master

    Update scalafmt-core to 3.2.1 Merge pull request #1235 from s… (compare)

  • Dec 03 11:53
    cquiroz closed #1235
  • Dec 03 09:05
    scala-steward closed #1233
  • Dec 03 09:05
    scala-steward commented #1233
  • Dec 03 09:05
    scala-steward opened #1235
  • Dec 01 19:43
    justjoheinz opened #1234
  • Dec 01 18:12
    julien-truffaut commented #1229
  • Dec 01 17:48
    scala-steward synchronize #1233
Ken Scambler
@kenbot
replace already only sets the value if it is present - this is why we renamed it from set, "replace" is supposed to suggest there's already a value
I'm not sure if you want us to second-guess your structure (sorry if not!), but a case class with fully optional members is often better represented by a Map
Shah Saraei
@ShahOdin

@julien-truffaut I have the same problem as here: https://stackoverflow.com/a/42668525/9199853 I tried to replicate your answer with the updated API:

  import monocle.macros.GenIso
  case class Alpha(text: String = "content")
  case class Beta(alpha: Alpha = Alpha())
  case class Gamma(beta: Option[Beta])
  val navigateToText = GenIso[Gamma, Option[Beta]]
    .andThen(GenIso[Beta, Alpha].asPrism.below[Option])
    .andThen(GenIso[Alpha, String].asPrism.below[Option])

it compiles. but if I add another field to Gamma, say: maybeI: Option[Int] it complains of:

Found several case class accessor for Gamma, Gamma needs to be a case class with a single accessor.

which makes sense now that I think about it. is there a way of solving the more generalised problem?

Shah Saraei
@ShahOdin
ok nvm, in general Beta might have multiple fields and with Gamme(None) it's not clear how we can create a Beta out of the blue which happens to have a nested Alpha. are there abstractions here that we could use to solve this problem?
Jan Bracker
@jbracker
What is the right monocle abstraction for an optional extractor aka "S => Option[A]" (an unapply method)? At first I thought I wanted a Prism or an Optional but both of those require a "reverse" route which I don't have. What I need is a Getter that delivers Option[A] instead of A. But if I use Getter[S, Option[A]] I need to flatten all of my results. Or is this something I should do with a special kind of Fold? I am unsure how the Monoid would work in that case...
Jan Bracker
@jbracker
Oh, I suppose this should work? override def foldMap[M](f: A => M)(s: S)(implicit monoid: Monoid[M]): M = unapply(s).fold(monoid.empty)(f)where unapply: S => Option[A]
Jan Bracker
@jbracker
Why are there no FoldLaws?
Julien Truffaut
@julien-truffaut
Foldable as no laws, I guess it could have some laws to check consistency between methods but that's it
Julien Truffaut
@julien-truffaut
felher
@felher

Hey folks :)

I'm trying to use monocle 3.0.0 with ScalaJS and Scala 3.0, but I'm getting Referring to non-existent class monocle.syntax.AppliedPLens$ as an error during fastLinkJS. Has anyone seen that before?

Julien Truffaut
@julien-truffaut
hey, could it be possible you have multiple monocle version in your path? (we renamed the organsiation)
felher
@felher
@julien-truffaut Sorry for the noise, I was just being dumb :)
But, for posterity, if someone makes the same mistake I did: Make sure, when using scalajs, that you have three, not two %%% (goes without saying, but I somehow missed it)
Julien Truffaut
@julien-truffaut
np :)
felher
@felher
Hey again ;)
Can I use focus to zoom into an index of list? Like person.focus(_.addresses(0)) ?
Wow, again. I found it... index. Sorry for the noise again. I have to be careful that doesn't become a running gag.
Ken Scambler
@kenbot
No worries, ask away! I'm glad it was discoverable
Hartmut Pfarr
@hartmut27
I use e.g. GenLens[MyType](_.abc.def) to build a lens for later usage, which works very very nice (Monocle 2.1.0 Scala 2.13).
In rare cases where e.g. a lens is passed to a function as a free parameter I would like I could sometimes additionally build a lens with "identity semantics": A lens which reflects the original object applied to the lens itself (and also a lens which does not change the optics when chained), using composeLens with a lens and "identity lenses" I would expect no effect on the result after executing the "lens chain".
I've tried GenLens[MyType](_) without success, GenLens[MyType](identity) does not compile, GenLens[MyType](x=>x) does not compile too.
Any hints? Eventually I've overseen something.
Julien Truffaut
@julien-truffaut
You can get an identity optics using Iso.id or Focus()
Hartmut Pfarr
@hartmut27
merci :) I'll check that
Julien Truffaut
@julien-truffaut
np
Actually in Moncole before 3.0.0, it must be Lens.id
Hartmut Pfarr
@hartmut27
ah I see
works perfectly :) :)
Matt Hughes
@matthughes

Upgrading to 3.0.0 and trying to switch to andThen but it’s causing ambiguous overloaded method in a lot of places.

                val x: Optional[State,Option[EiaChannelNumber]] = Lenses.muxEiaChannel(idx)
                val y: Optional[State,EiaChannelNumber] = x.andThen(some)
                // Overloaded method andThen 
                // Lenses.muxEiaChannel(idx).andThen(some)

It works if I explicitly type the intermediate variables but it does not like to be chained. Any tips?

Ken Scambler
@kenbot
By moving to a single overloaded compose method, we traded away some type inference for convenience. To mitigate this, there are now extension methods for common generic operations like each, some, index, at, etc
You should be able to do x.some
Ken Scambler
@kenbot
Lenses.muxEiaChannel(idx).some
Matt Hughes
@matthughes
Oh yeah .some works. Is there a similar trick for avoiding the conflict between Cats’ index method and Monocle’s?
If I remove all of cats.syntax.all._, index works as expected
Matt Hughes
@matthughes
I can get around it by eliminating that one implicit but this is kind of gross: import cats.syntax.all.{catsSyntaxIndex => _, _}. That’s the name of an implicit def; not sure how stable to expect that identifier to be over time.
Julien Truffaut
@julien-truffaut
sorry about that, we'll try to improve this
Matt Hughes
@matthughes
thanks. Monocle 3 has been great so far. Love the unified API
Julien Truffaut
@julien-truffaut
Great. It would be nice to have a test so that we can detect this sort of conflict with cats
Ken Scambler
@kenbot
We have an open issue already, hopefully we'll have a fix or workaround soon. optics-dev/Monocle#1183
Matt Hughes
@matthughes
Has there been any discussion of moving to the Typelevel discord?
Julien Truffaut
@julien-truffaut
Nothing official. Personally, I don't have a strong preference.
Bob Glamm
@glamm

Ok, in a source file that just imports from the monocle namespace, I have:

val projectListLens = Iso.id[List[Project]].asLens
def indexedProjectLens(projectId: Int) = projectListLens.index(projectId)

and all seems good. Then, in a separate source file that imports from monocle as well as from cats, I have:

val  projectLens = indexedProjectLens(projectId)     // this is ok
val plens = projectListLens.index(projectId)   // this is not ok

with a type mismatch on projectId: found projectId.type (underlying type Int), expected cats.Representable.Aux[monocle.PLens[...]]

How do I make the latter (val plens = ...) work when cats names are imported?

... and, as I scroll up I see that maybe this is exactly optics-dev/Monocle#1183
Julien Truffaut
@julien-truffaut
yes, that's correct
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.