by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Nick
    @stanch
    Hey, could you point out main advantages over https://github.com/adamw/quicklens ?
    I suppose it’s just greater flexibility stemming from monocle?
    Jan Christopher Vogt
    @cvogt
    @stanch I haven’t used quicklens, but I really like the API of xdotai/lens.
    x.lens(_.a.b.c).set(5)
     .lens(_.a.b.d).modify(_ + 2)
    Nick
    @stanch
    this is exactly the same as quicklens, sans some renaming :)
    Jan Christopher Vogt
    @cvogt
    it doesn’t get much closer to
    x.a.b.c = 5
    x.a.b.d = x.a.b.d + 2
    Nick
    @stanch
    x.modify(_.a.b.c).setTo(5)
     .modify(_.a.b.d).using(_ + 2)
    this is quicklens
    but it also has x.modify(_.a.b.each) when b is a Functor
    and other nice features
    Jan Christopher Vogt
    @cvogt
    I see. I like lens’ naming ;).
    And that’s all lens does.
    quicklens seems to have broader focus, more features. We have not needed anything else, so something more feature rich would actually be more complicated for use. But if you do quicklens, might be nice.
    It seems to me, that collections already have mutator methods, i.e. .map, .flatMap, etc.
    Nick
    @stanch
    we are using quicklens extensively at work, I even contributed a bunch of features, e.g. support for sealed traits in addition to case classes, “prisms”, etc
    Jan Christopher Vogt
    @cvogt
    Something like .each seems like just a different way to do something that already exists. But I might be wrong. Or it might well be that the syntax gets much nicers using something like an .each for functors.
    Nick
    @stanch
    actually “.each” is super handy when many of the fields in the data model are Options
    Jan Christopher Vogt
    @cvogt
    We only wanted to solve the .copy problem we had, so that’s what lens does :).
    You got an example for the Option thing?
    Nick
    @stanch
    here’s one I wrote for the docs (for .modifyAll):
    Jan Christopher Vogt
    @cvogt
    We have try to limit the need for .copy/.lens as much as possible, because it seems harder to reason about than trying to construct the desired values in the first place.
    Nick
    @stanch
    case class Person(firstName: String, middleName: Option[String], lastName: String)
    
    val person = Person("john", Some("steve"), "smith")
    
    person.modifyAll(_.firstName, _.middleName.each, _.lastName).using(_.capitalize)
    you can say person.modify(_.middleName).using(_.map(_.capitalize)) of course
    Jan Christopher Vogt
    @cvogt
    I see. Yeah, might be nice syntax when you have a lot of need for it.
    Nick
    @stanch
    but person.modify(_.middleName.each).using(_.capitalize) is a bit nicer
    Jan Christopher Vogt
    @cvogt
    :thumbsup:
    Nick
    @stanch
    I was just curious about your lib because I’m trying to be up to date on lenses in Scala :)
    actually my first opensource project in Scala was along the lines of quicklens and lens
    Jan Christopher Vogt
    @cvogt
    ah interesting.
    Nick
    @stanch
    btw if by any chance you need to explain lens to you colleagues, I have some cool lens visualizations here: https://github.com/stanch/unzimm#lens ;)
    based on Monocle
    Jan Christopher Vogt
    @cvogt
    Yeah, I really tried to keep it simple with .lens. The .copy problem seems to be one of the most common ones and if lens can solve it for some people it has served it’s purpose.
    cool, will link it in our internal wiki. thx
    Nick
    @stanch
    example
    this is the sort of thing it produces