Last active
January 28, 2019 17:47
-
-
Save nikita-leonov/7b45b102a12c3c1e6fb0eaba1231fb7b to your computer and use it in GitHub Desktop.
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
| import Focus // https://github.com/typelift/Focus | |
| struct Foo { | |
| let bar: Int | |
| let baz: Bool | |
| static let bar = SimpleLens(get: { | |
| $0.bar | |
| }, set: { (oldFoo, newBar) in | |
| Foo(bar: newBar, baz: oldFoo.baz) | |
| }) | |
| static let baz = SimpleLens(get: { | |
| $0.baz | |
| }, set: { (oldFoo, newBaz) in | |
| Foo(bar: oldFoo.bar, baz: newBaz) | |
| }) | |
| } | |
| let foo = Foo(bar: 0, baz: false) | |
| Foo.baz.set(foo, true) // Foo(bar: 0, baz: true) | |
| Foo.bar.set(foo, 100) // Foo(bar: 1000, baz: false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment