Skip to contents

Splits items into requests of at most size and calls fn once per batch.

Usage

batched(fn, items, size, ..., policy = list())

Arguments

fn

Function called with each batch as its first argument.

items

Vector or list of items to split.

size

Positive integer maximum number of items per batch.

...

Additional arguments passed unchanged to fn.

policy

Named list of explicit client choices: normalize(items), build(chunk, index), and merge(results) functions; on_error set to stop by default, or drop/keep for recovery with warnings; error_result retained by keep; and first_batch_only = TRUE for explicit legacy pagination compatibility. Normalization, construction and merging errors always propagate.

Value

A named list of unmerged results, one per batch, unless a merge function is selected.

Details

Inputs and order are preserved by default. Every chunk calls the supplied function through its existing authentication, query, retry and response policy. The companion performs no HTTP or response decoding. Optional normalization may remove duplicates, missing and empty values. Optional construction may preserve singleton JSON arrays with as.list or join raw text explicitly.

Examples

batched(sum, 1:5, 2)
#> $`1`
#> [1] 3
#> 
#> $`2`
#> [1] 7
#> 
#> $`3`
#> [1] 5
#>