Effect CommunityEC
Effect Community5mo ago
35 replies
Afonso Matos

Using Execution Plans in Effect Typescript for More Ergonomic Code

I'm just wondering if you've seen this pattern and recommend it?
It feels much more ergonomic than using the execution plan directly:

But at the same time feels a bit hacky?

const executionPlan = ExecutionPlan.make({ provide: Gemini_2_5_Flash_Lite }, { provide: Gemini_2_5_Pro });
const ModelFallback = Layer.effect(
    AiLanguageModel.AiLanguageModel,
    Effect.gen(function* () {
        return {
            generateObject: flow(AiLanguageModel.generateObject, Effect.withExecutionPlan(executionPlan)),
            generateText: flow(AiLanguageModel.generateText, Effect.withExecutionPlan(executionPlan)),
            streamText: flow(AiLanguageModel.streamText, Stream.withExecutionPlan(executionPlan))
        };
    })
);
Was this page helpful?