Suggested replacement for Effect.init(_ work: @escaping () -> Output)

I'm updating my app to use the latest release of TCA. I was using the version before "callback" was changed to "subscriber".

Previously there was this initializer for Effect:

public init(_ work: @escaping () -> Output) {
self = Deferred { Just(work()) }.eraseToEffect()
}

This is gone and I don't see a direct replacement, something doing Deferred { Just....

I'm curious why this initializer is no longer supported and what the recommended replacement is. Thanks!

This was changed when we decided to introduce a Failure to the Effect type, so some of the convenience initializers got a little messy. What you want is the .result static constructor:

Effect.result { .success(42) }
1 Like