Layer.empty

Sometimes you want to create a Layer that does not provide or require any services. You can do this with Layer.empty.

import { Layer } from "effect";

//      ┌─── Layer.Layer<never, never, never>
//      ▼
const empty = Layer.empty;
const stillEmpty = Layer.merge(Layer.empty, Layer.empty);
const alsoEmpty = Layer.provide(Layer.empty, Layer.empty);

Note that Layer.empty is a value, not a function. This is different from Context.empty (22) . The reason we need to call Context.empty is because it is non-effectful, whereas Layer.empty represents an Effect behind the scenes.

As with Context.empty, an empty layer is often helpful as a base value for functions that combine many layers.

We can implement Layer.empty very easily. Here are two example implementations.

import { Context, Effect, Layer } from "effect";

export const empty = Layer.succeedContext(Context.empty());

export const empty2 = Effect.sync(Context.empty).pipe(Layer.effectContext);

Let’s recap:

  • A Layer represents an Effectful constructor
  • Layer.empty represents a constructor that does nothing
  • An empty layer is helpful as a base value or placeholder