Skip to content

Instantly share code, notes, and snippets.

@twittemb
Created July 15, 2018 18:24
Show Gist options
  • Select an option

  • Save twittemb/a44e3bc3ba7ff38eecff59035c8dd39e to your computer and use it in GitHub Desktop.

Select an option

Save twittemb/a44e3bc3ba7ff38eecff59035c8dd39e to your computer and use it in GitHub Desktop.
struct Lens<A,B> {
let from : A -> B
}
let firstname = Lens<Contact, String>(from: { $0.user.firstname })
...
let myContact = Contact(user: User(firstname: "James", lastname: "Kirk"),
isConnected: true)
firstname.from(myContact) // will return "James"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment