> For AI agents: the complete documentation index is available at https://viteval.dev/llms.txt, the full documentation bundle is available at https://viteval.dev/llms-full.txt.

# `sampleItems()`

Create a dataset generator from a single-item factory and a fixed count.
This generates new items. It does not sample an existing array.

## Import

```ts
import { sampleItems } from 'viteval/dataset';
```

## Signature

```ts
function sampleItems<DATA_ITEM extends DataItem>(
  params: SampleItemsParams<DATA_ITEM>
): Result<() => Promise<DATA_ITEM[]>>;
```

## Parameters


Parameters

paramsSampleItemsParams<DATA_ITEM>required

Item count and generator factory.

Properties

countnumberrequired

A positive safe integer. Zero, negative, fractional, and non-finite
values return an error Result without calling the factory.

item(index: number) => DATA_ITEM | Promise<DATA_ITEM>required

Factory receiving a zero-based index. Items are generated sequentially
in index order whenever the returned generator is called.

## Example

```ts
import { defineDataset, sampleItems } from 'viteval/dataset';

const sampled = sampleItems({
  count: 20,
  item: (index) => ({
    input: `What is ${index} + 1?`,
    expected: String(index + 1),
  }),
});
if (!sampled.ok) throw sampled.error;

export default defineDataset({
  name: 'addition',
  data: sampled.value,
});
```

## Return value and errors

Returns a synchronous `Result` containing an asynchronous generator. Calling
`sampleItems()` validates the count but does not generate cases. If the item
factory throws or rejects later, the generator rejects. When used by
`evaluate()`, that is an evaluation data-loading failure.

See [defineDataset()](https://viteval.dev/api/define-dataset.md) for persistence and overwrite behavior.
