Skip to content

Instantly share code, notes, and snippets.

@nikita-leonov
Last active January 28, 2019 17:47
Show Gist options
  • Save nikita-leonov/7b45b102a12c3c1e6fb0eaba1231fb7b to your computer and use it in GitHub Desktop.
Save nikita-leonov/7b45b102a12c3c1e6fb0eaba1231fb7b to your computer and use it in GitHub Desktop.
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