choices
The possibilities of a choice, with their weights.
Call Signature
function choices<T>(list): Choices<T>;Defined in: packages/core/src/choices/choices.ts
choices([{ value, weight }, …]), or the possibilities alone, equally weighted:
choices(['keep', 'fill']) or choices('keep', 'fill'). Weights must be non-negative and sum
to one, and no tag may appear twice. A weighted possibility has only value and weight: with
anything more it throws, and a possibility that is itself such an object is written weighted.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
list | readonly Possibility<T>[] |
Returns
Choices<T>
Example
import { choices } from '@reintent/core';
type Layout = { kind: 'grid'; columns: number } | { kind: 'list' };
// A prior: weights that sum to one.
const layouts = choices<Layout>([
{ value: { kind: 'grid', columns: 3 }, weight: 0.7 },
{ value: { kind: 'list' }, weight: 0.3 },
]);
console.log(layouts[0]); // → { value: { kind: 'grid', columns: 3 }, weight: 0.7 }
// The possibilities alone: equally weighted, which says nothing (no prior).
const tones = choices('formal', 'warm');
console.log(tones);
// → [ { value: 'formal', weight: 0.5 }, { value: 'warm', weight: 0.5 } ]Call Signature
function choices<T>(list): Choices<T>;Defined in: packages/core/src/choices/choices.ts
choices([{ value, weight }, …]), or the possibilities alone, equally weighted:
choices(['keep', 'fill']) or choices('keep', 'fill'). Weights must be non-negative and sum
to one, and no tag may appear twice. A weighted possibility has only value and weight: with
anything more it throws, and a possibility that is itself such an object is written weighted.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
list | readonly T[] |
Returns
Choices<T>
Call Signature
function choices<T>(...values): Choices<T>;Defined in: packages/core/src/choices/choices.ts
choices([{ value, weight }, …]), or the possibilities alone, equally weighted:
choices(['keep', 'fill']) or choices('keep', 'fill'). Weights must be non-negative and sum
to one, and no tag may appear twice. A weighted possibility has only value and weight: with
anything more it throws, and a possibility that is itself such an object is written weighted.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
...values | T[] |
Returns
Choices<T>
Last updated on
Edit on GitHub