Skip to content

Reader

Reader<R, A> = (env) => A

Defined in: Core/Reader.ts:26

A computation that reads from a shared environment R and produces a value A. Use Reader to thread a dependency (config, logger, DB pool) through a pipeline without passing it explicitly to every function.

R

A

R

A

type Config = { baseUrl: string; apiKey: string };

const buildUrl = (path: string): Reader<Config, string> =>
  (config) => `${config.baseUrl}${path}`;

const withAuth = (url: string): Reader<Config, string> =>
  (config) => `${url}?key=${config.apiKey}`;

const fetchEndpoint = (path: string): Reader<Config, string> =>
  pipe(
    buildUrl(path),
    Reader.chain(withAuth)
  );

// Inject the config once at the edge
fetchEndpoint("/users")(appConfig); // "https://api.example.com/users?key=secret"