'Builds a function that sorts the indexed results.
Args:
extra_hook: A function that the returned function will apply to its result
before returning.
Returns:
A function that takes a list of results and reorders them to match the
order in which the input values associated with each results were
originally provided.'

def __sort_result_index_pairs(self, extra_hook):

    def sort_result_index_pairs(result_index_pairs):
        results = ([None] * len(result_index_pairs))
        for (result, index) in result_index_pairs:
            results[index] = result
        if (extra_hook is not None):
            results = extra_hook(results)
        return results
    return sort_result_index_pairs
