Created
January 17, 2016 18:22
-
-
Save mbrandonw/284c41a5dcf3837a2b43 to your computer and use it in GitHub Desktop.
Making `Lens<Whole, Part>` into a functor
This file contains hidden or 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
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