Last active
August 29, 2015 14:06
-
-
Save amirrajan/78148ab6f98a21b1d9b6 to your computer and use it in GitHub Desktop.
Lenses, Scalaz and Scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val firstEventL = Lens.lensu[EventContainer, Event]( | |
(container, value) => container.copy(events = Seq(value) ++ container.events.tail), _.events.head) | |
val profileL = Lens.lensu[Event, Profile]( | |
(event, value) => event.copy(profile = value), _.profile) | |
val reservationL = Lens.lensu[Profile, Reservation]( | |
(profile, value) => profile.copy(reservation = value), _.reservation) | |
val settingAllProperties = | |
firstEventL =>= | |
{ _.copy(eventTitle = "New Title") } andThen | |
firstEventL >=> profileL =>= | |
{ _.copy(profileName = "New Profile Name") } andThen | |
firstEventL >=> profileL >=> reservationL =>= | |
{ | |
_.copy( | |
reservationComments = "New Comments", | |
spaceReservations = Seq( | |
SpaceReservation(1111), | |
SpaceReservation(2222))) | |
} apply ec | |
val settingJustOneProperty = | |
firstEventL >=> profileL >=> reservationL =>= | |
{ _.copy(reservationComments = "New Comments") } apply ec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment