MCPcopy
hub / github.com/apify/crawlee / reduce

Method reduce

packages/core/src/storages/dataset.ts:586–607  ·  view source on GitHub ↗
(
        iteratee: DatasetReducer<T, Data>,
        memo?: T,
        options: DatasetIteratorOptions = {},
    )

Source from the content-addressed store, hash-verified

584 async reduce<T>(iteratee: DatasetReducer<T, Data>, memo: T, options?: DatasetIteratorOptions): Promise<T>;
585
586 async reduce<T = Data>(
587 iteratee: DatasetReducer<T, Data>,
588 memo?: T,
589 options: DatasetIteratorOptions = {},
590 ): Promise<T | undefined> {
591 checkStorageAccess();
592
593 let currentMemo: T | undefined = memo;
594
595 const wrappedFunc: DatasetConsumer<Data> = async (item, index) => {
596 if (index === 0 && currentMemo === undefined) {
597 currentMemo = item;
598 } else {
599 // We are guaranteed that currentMemo is instanciated, since we are either not on
600 // the first iteration, or memo was already set by the user.
601 currentMemo = await iteratee(currentMemo as T, item, index);
602 }
603 };
604
605 await this.forEach(wrappedFunc, options);
606 return currentMemo;
607 }
608
609 /**
610 * Iterates over dataset items using an async generator,

Callers 15

discoverValidSitemapsFunction · 0.80
parseOpenGraphPropertyFunction · 0.80
parseOpenGraphFunction · 0.80
weightedAvgFunction · 0.80
getCurrentCpuTicksFunction · 0.80
_launchMethod · 0.80
getCurrentCpuTicksMethod · 0.80
MinimumSpeedStreamFunction · 0.80
sumFunction · 0.80
resultCountMethod · 0.80
makeTextFunction · 0.80

Calls 2

forEachMethod · 0.95
checkStorageAccessFunction · 0.90

Tested by 1

makeTextFunction · 0.64