Effect CommunityEC
Effect Community•3y ago•
3 replies
pigoz

Creating a Layer from the Output of Another Layer

I think I need some Layer help 🙂 I really wanted to create a layer from the output of another layer (spin up test container using Layer.scoped => build pg client with test container url). Using Layer.flatMap I get a Context<PgContainer> instead of PgContainer. This is the only way I got it to typecheck.

import * as Pg from "@sqlfx/pg";
import { PgTestContainerLayerTag, PgTestContainerLayer } from "./containers";

export const PgTest = Layer.provide(
  PgTestContainerLayer,
  Layer.scoped(
    Pg.tag,
    PgTestContainerLayerTag.pipe(
      Effect.flatMap((_) => Pg.make({ database: _.url }))
    )
  )
); 
Was this page helpful?