-
-
Save ennioma/913c70a861d9174f79751b3b770f2a96 to your computer and use it in GitHub Desktop.
Lenses Composition
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
precedencegroup ComposePrecedence { | |
associativity: left | |
} | |
infix operator >>> : ComposePrecedence | |
func >>> <Container, View, Subview>(lhs: Lens<Container, View>, rhs: Lens<View, Subview>) -> Lens<Container, Subview> { | |
return Lens( | |
get: { container in | |
let view = lhs.get(container) | |
let subview = rhs.get(view) | |
return subview | |
}, | |
set: { (container, subview) in | |
let initialView = lhs.get(container) | |
let updatedView = rhs.set(initialView, subview) | |
return lhs.set(container, updatedView) | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment