Lenses: fields as values

"Lenses: fields as values" by Seth Tisue (Northwestern University)

Lenses aren’t in the Scala standard library, but two libraries provide them: Scalaz and Miles Sabin’s Shapeless. I’ll show how you to use the Shapeless version, and we’ll look at how it’s implemented.

A lens represents a readable and “settable” location in a possibly nested immutable object. (“Settable” is in quotes because we make a new object rather than mutating the old one.)

This may interest you if:

...you use immutable objects

...you use nested immutable objects

...you want to abstract over different fields in your immutable objects

...you're interested in functional programming

This will overlap a lot with Ed Kmett's 2011 talk on the same subject. If you saw and completely grasped Ed's talk, you might not learn much from this one. Compared to Ed's, my take will be more elementary and less formal. (And I'll be covering only lenses themselves, not bringing in the state monad too.)

hangout afterwards at Catalyst (300 Technology Square, by Main & Albany)

Note this is in a different room than usual.

It's easy to get lost in the Stata Center, so allow some extra time. Enter the building at 32 Vassar Street, opposite the sign for 43 Vassar Street. Take the elevator (under a sign saying "Alexander W Dreyfoos Building" to the fourth floor. (If you find yourself instead in the Gates Building part of the Stata Center, you will need to walk to the other end of the buildling to the Dreyfoos elevators.) Turn left out of the elevator, then immediately turn right, go through the double doors, walk almost all the way across the orange carpeted area, and look for room 32-G449 on your right.

We have had recurring trouble with the building doors being locked despite our requests. If this happens, usually there are enough people coming and going that if you wait a few minutes, someone will enter or leave and you can go in.

Join or login to comment.

  • Seth T.

    someone asked, why immutable objects? why not just use vars? very good question, but a big question. I think Martin Odersky answers this well in his Scala Exchange keynote at http://skillsmatter.com/podcast/scala/keynote-martin-odersky, minutes 15:00 to 33:00. the talk is from earlier this week and also has up to date info on Scala 2.10

    November 21, 2012

    • Stephen J.

      My view is that re-creating the universe every time is the principal feature of immutable objects. It means that each time I do an update I still have the previous state - I didn't destroy anything. This does force a different way of solving the problem though. Rich Hickey, the creator of Clojure, has a really good presentation on this: http://www.infoq.com/...­

      November 21, 2012

    • Seth T.

      I've now responded at greater length at https://groups.google....­

      December 1, 2012

  • Douglas A.

    I have uploaded the video I shot of the talk. Here it is:

    http://www.youtube.com/watch?v=BiHH3LzKV04

    Sorry, Seth, you're barely visible in it, but your slides look great!

    November 28, 2012

    • Seth T.

      thank you — much appreciated

      November 29, 2012

  • Edward K.

    After the talk, I showed a port of Seth's Turtle example to Haskell. I've added it to the lens repository as an "official" lens example: https://github.com/ekmett/lens/blob/master/examples/Turtle.hs

    November 21, 2012

  • A former member
    A former member

    I'd seen lenses, but I'd never built anything with them before..this talk solidified my understanding. Thanks for keeping it straightforward and motivated by clear, real-world problems. Nice work Seth!

    November 19, 2012

  • James P.

    s/soda/beer/g

    November 19, 2012

  • Andy O.

    Too bad we didn't hear more about Scalaz, promoted as quite powerful. Good presentation on the topics that were covered. Nice audience interaction.

    November 19, 2012

  • Steve N.

    Great. High enough level for me to learn a lot, but no so high that this beginner/intermediate couldn't follow.

    November 19, 2012

  • Nermin Š.

    There will be pizza and salads, sponsored by Capital IQ.

    November 19, 2012

  • Seth T.

    Do we have a volunteer to record the talk? Ed Kmett said he could record it on his iPad, but the quality might not be so good. If someone with better equipment is available, it would be appreciated.

    November 14, 2012

    • Douglas A.

      I can record it. I've recorded a couple in the past. The audio doesn't come out so great, however, since the camera has no support for a separate microphone.

      November 18, 2012

  • Oliver R.

    What is a lens?

    November 11, 2012

    • James P.

      Getters/setters without mutation: http://www.youtube.co...­

      November 11, 2012

    • Seth T.

      I've expanded the talk description a bit, including some compare/contrast with how Ed covered this same subject last year (in the talk James links to).

      November 12, 2012

Our Sponsors

  • Akamai Technologies

    provides meetup space and food/drinks.

  • CodeReactive

    sponsoring Meetup dues

  • Localytics

    Provides meetup space and food/drinks.

People in this
Meetup are also in:

Create your own Meetup Group

Get started Learn more
Allison

Meetup has allowed me to meet people I wouldn't have met naturally - they're totally different than me.

Allison, started Women's Adventure Travel

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy