Last active
August 22, 2017 14:42
-
-
Save MartinMoizard/63af25fe5f97c1e8ba40ba195ff6cbe5 to your computer and use it in GitHub Desktop.
This file contains 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
final class SayHelloViewModel: ViewModelType { | |
struct Input { | |
let name: Observable<String> | |
let validate: Observable<Void> | |
} | |
struct Output { | |
let greeting: Driver<String> | |
} | |
func transform(input: Input) -> Output { | |
let greeting = input.validate | |
.withLatestFrom(input.name) | |
.map { name in | |
return "Hello \(name)!" | |
} | |
.startWith("") | |
.asDriver(onErrorJustReturn: ":-(") | |
return Output(greeting: greeting) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment