Reputation: 2836
In a operator chain like this you used to be able to return Publishers.Just(defaultValue) but it is deprecated and I can't find a way to do this functionality anymore. What is the new way to return a defaultValue?
$query
.throttle(for: 0.5, scheduler: DispatchQueue.main, latest: true)
.removeDuplicates()
.map { query -> AnyPublisher<[Repo], Never> in
guard query.count >= 3 else {
return Publishers.Just([])
.eraseToAnyPublisher()
}
return API().search(with: query)
.retry(3)
.eraseToAnyPublisher()
}
Upvotes: 2
Views: 2156
Reputation: 1520
I was able to get this to work:
Result.Publisher([])
.eraseToAnyPublisher()
If you need to send back just an error, you'll likely need to specify the type as well:
Result<YourObject, YourError>.Publisher(.failure(YourError.error))
.eraseToAnyPublisher()
Upvotes: 3