What’s the alternative for 'Publishers.Once'?

In Xcode 11 beta 4, Publishers.Once was renamed Result.Publisher (where Result is part of the standard library). So write this instead:

return Result.Publisher(()).eraseToAnyPublisher()

Apple also added a publisher property to Result, which is convenient if you already have a Result:

let result: Result<Void, Error> = someFunction()
return result.publisher.eraseToAnyPublisher()

setFailureType(to:) could be a solution for some paticular cases:

return Just(()).setFailureType(to: Error.self).eraseToAnyPublisher()

But please note that Rob's answer is generally preferable. That is simpler and probably faster.

Tags:

Swift

Combine