Created
January 30, 2020 10:19
-
-
Save ramunasjurgilas/e18766e2ccf14eca4590c97ab616c804 to your computer and use it in GitHub Desktop.
flatMap() as transforming operator
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
struct Person { | |
var name: String | |
let age: CurrentValueSubject<Int, Never> | |
init(name: String, age: Int) { | |
self.name = name | |
self.age = CurrentValueSubject(age) | |
} | |
} | |
var person = Person(name: "Mark", age: 18) | |
let age = CurrentValueSubject<Person, Never>(person) | |
age | |
.flatMap { $0.age } | |
.sink { print($0) } | |
person.age.value = 45 | |
person.name = "Kobra" | |
// Output: | |
// 18 | |
// 45 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment