Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lenses Composition
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