Question about dynamically providing different service implementations in Effect TypeScript library

export const upsertWorkspaceIntegrationUseCase = ({
  workspaceId,
  request,
}: {
  workspaceId: typeof WorkspaceId.Type;
  request: typeof UpsertWorkspaceIntegrationRequest.Type;
}) =>
  Effect.gen(function* () {
    const workspaceIntegrationsService = yield* WorkspaceIntegrationsService;

    const integrationService = yield* TimeTrackingIntegrationService;

    return yield* workspaceIntegrationsService.upsertWorkspaceIntegration({
      workspaceId: workspaceId,
      workspaceIntegration: {
        kind: request.kind,
        apiKeyUnencrypted: request.apiKeyUnencrypted,
      },
    });
  }).pipe(
    Effect.provide(
      Match.value(request).pipe(
        Match.when(
          { kind: "float" },
          () => TimeTrackingIntegrationService.floatLive
        ),
        Match.orElse(() =>
          Effect.fail(new Error("Unsupported integration kind"))
        )
      )
    )
  );


How would I dynamically "provide" or pick a different service implementation?

The Effect.fail does not seem to play nicely with the Effect.provide. But maybe this is also the wrong pattern all together
Was this page helpful?