Type inference when using `Effect.throttle` operator

I'm trying out composable core location. This is the piece of code that throttles reporting of location to every 15 seconds. However I get loads of compilation errors:

    case .locationManager(.didUpdateLocations(let locations)):
        state.lastLocations = locations
        return Effect(value: AppAction.reportLocation)
            .throttle(
                id: env.reportId,
                for: 15,
                scheduler: env.scheduler,
                latest: true
            )

env.scheduler is AnyScheduler<DispatchQueue>, env.reportId is simple hashable struct. This is how it looks like when I try to compile the code:

Judging from extra argument error I think it infers the throttle method on Publisher type rather than Effect directly. Any help is appreciated.

The throttle operator on Effect is still internal at the moment: swift-composable-architecture/Throttling.swift at 37537a5248eeff8030111735b8584ebd664b47a8 · pointfreeco/swift-composable-architecture · GitHub

So I think the error you're seeing is that it's trying to call the more general Combine.Publisher.throttle method.

If you copy and paste the above file into your project, it should work just fine.

We've had some recent interest in marking this public, but could use a few more folks kicking the tires to make sure everything works as expected. Please let us know your experience!

1 Like

It's weird how Xcode allowed me to jump into definition of Effect's internal implementation. Very misleading :grimacing:

Thanks, I will kick tires a bit :slight_smile:

I ran into an interesting issue and reported it here.