Main Content


An iterator over intermediate values for use with mapreduce


The mapreduce function automatically creates a ValueIterator object during execution and uses it to store the values associated with each unique intermediate key added by the map function. Although you never need to explicitly create a ValueIterator object to use mapreduce, you do need to interact with this object in the reduce function. Use the hasnext and getnext object functions to retrieve the values associated with each unique key in the intermediate KeyValueStore object.


The mapreduce function automatically creates ValueIterator objects during execution.


expand all

This property is read-only.

Intermediate key, specified as a numeric scalar or character vector. Key is one of the unique keys added by a map function. All the values in the ValueIterator object are associated with this key.

Object Functions

hasnextDetermine if ValueIterator has one or more values available
getnextGet next value from ValueIterator


collapse all

Use the hasnext and getnext functions in a while loop within the reduce function to iteratively get values from the ValueIterator. For example,

function MeanDistReduceFun(sumLenKey, sumLenIter, outKVStore)
    sumLen = [0, 0];
    while hasnext(sumLenIter)
        sumLen = sumLen + getnext(sumLenIter);
    add(outKVStore, 'Mean', sumLen(1)/sumLen(2));

Always call hasnext before getnext to confirm availability of a value. mapreduce returns an error if you call getnext with no remaining values in the ValueIterator.

Version History

Introduced in R2014b