Skip to content

Instantly share code, notes, and snippets.

@mbrandonw
Created January 17, 2016 18:22
Show Gist options
  • Save mbrandonw/284c41a5dcf3837a2b43 to your computer and use it in GitHub Desktop.
Save mbrandonw/284c41a5dcf3837a2b43 to your computer and use it in GitHub Desktop.
Making `Lens<Whole, Part>` into a functor
struct Lens<A, B> {
let get: A -> B
let set: (B, A) -> A
func map <C> (f: B -> C) -> Lens<A, C> {
return Lens(
get: { f(get($0)) },
set: { set(f($0), $1) }
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment