Skip to content

Instantly share code, notes, and snippets.

@ramunasjurgilas
Created January 30, 2020 08:46
Show Gist options
  • Save ramunasjurgilas/745110630725759661f14b3b2f1b853a to your computer and use it in GitHub Desktop.
Save ramunasjurgilas/745110630725759661f14b3b2f1b853a to your computer and use it in GitHub Desktop.
map(_:) KeyPath as transforming operator
struct Person {
let firstName: String
let lastName: String
}
let publisher = PassthroughSubject<Person, Never>()
publisher
.map(\.firstName, \.lastName).sink {
print("\($0) \($1)")
}
let person = Person(firstName: "Jackie", lastName: "Chan")
publisher.send(person)
// Output:
// Jackie Chan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment