Skip to content
party.js logoparty.js logo

ReferenceSamplersFunction

evaluateSampler()

Resolves a sampler to a value.

function evaluateSampler<T>(sampler: Sampler<T>, ctx: SamplerContext): T;

Resolves a Sampler to a value, by calling it if it is a function, or returning it unchanged if it is a fixed value.

This can be useful when writing your own samplers that build on other samplers.

T
samplerSampler<T>

The sampler to resolve.

ctxSamplerContext

The context to pass on if the sampler is a function.

T

The sampled value.

const doubled =
(base: Sampler<number>): SamplerFn<number> =>
(ctx) =>
2 * evaluateSampler(base, ctx);