Effect CommunityEC
Effect Community3y ago
37 replies
steida

Comparing Layer.provide and Layer.use for Effect docs

Effect docs recommend Layer.provide, but Layer.use seems to be less verbose and more readable. What do you prefer?


// Layer.provide
export const dbWorker = DbWorker.pipe(
  Effect.provideLayer(
    Layer.mergeAll(
      SqliteLive,
      Bip39Live,
      Layer.merge(HmacLive, Sha512Live).pipe(Layer.provide(Slip21Live)),
      NanoIdLive,
      SyncWorkerLive,
    ).pipe(Layer.provide(DbWorkerLive)),
  ),
  Effect.runSync,
);

// Layer.use
export const dbWorker2 = DbWorker.pipe(
  Effect.provideLayer(
    Layer.use(
      DbWorkerLive,
      Layer.mergeAll(
        SqliteLive,
        Bip39Live,
        Layer.use(Slip21Live, Layer.merge(HmacLive, Sha512Live)),
        NanoIdLive,
        SyncWorkerLive,
      ),
    ),
  ),
  Effect.runSync,
);
Was this page helpful?