Skip to content

Instantly share code, notes, and snippets.

@hsavit1
Forked from mbrandonw/lens-functorial.swift
Created January 17, 2016 23:42
Show Gist options
  • Save hsavit1/0a9b9a05dbc79fa99f42 to your computer and use it in GitHub Desktop.
Save hsavit1/0a9b9a05dbc79fa99f42 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