aaa

aaa
mail@pastecode.io avatar
unknown
swift
3 years ago
640 B
2
Indexable
Never
    func getGames() -> Observable<[Game]> {
        return localData.getGames()
            .map { GameMapping.gameEntityToDomain(gameEntity: $0) }
            .filter { !$0.isEmpty }
            .ifEmpty(switchTo: remoteData.getGames()
                        .map { GameMapping.gameResponseToEntity(gameResult: $0) }
                        .flatMap { self.localData.saveGames(gameEntity: $0) }
                        .filter { $0 }
                        .flatMap { _ in self.localData.getGames()
                            .map { GameMapping.gameEntityToDomain(gameEntity: $0) }
                        }
            )
        
    }