Skip to main content
Version: v0.0.6

Function: resolveMix()

resolveMix<T>(allowed, requested, fallback): readonly T[]

Resolve every entry of a caller-supplied corpus mix, in order, or fail closed on the first unrecognised one.

It substitutes the default only when the caller supplied nothing, which is exactly what the ?? it replaced did. An empty array is a supplied mix and is returned as one. An earlier version of this function also treated [] as "nothing supplied", on the stated grounds that it matched the previous behaviour; it did not - ?? fires on undefined and never on [] - and it changed the result of six published entry points, turning an explicit empty selection into "generate one of everything". A convenience that fails open is not a convenience.

Type Parameters

T

T extends string

Parameters

allowed

readonly T[]

Every kind the corpus may generate.

requested

readonly string[] | undefined

The mix the caller supplied, or undefined for the default.

fallback

readonly T[]

The default mix, used only when requested is undefined.

Returns

readonly T[]

The resolved mix.

Throws

SynthError SYNTH_UNSUPPORTED_KIND on the first unrecognised entry.

Example

import { resolveMix } from "@cosyte/synth";
resolveMix(["Result", "Order"] as const, ["Order"], ["Result", "Order"]); // ["Order"]