%ReduceTaskResult
% A data class that stores the results of a partitioned Reduce Task.

%   Copyright 2014-2016 The MathWorks, Inc.

classdef (Sealed, Hidden) ReduceTaskResult < parallel.internal.mapreduce.AbstractTaskResult
    properties (SetAccess = immutable)
        OutputFiles = {}; % An array of output files.
    end
    
    methods
        % Create a ReduceTaskResult.
        % Syntax:
        %   result = ReduceTaskResult()
        %   result = ReduceTaskResult(outputFiles, keyType, valueType)
        function obj = ReduceTaskResult(outputFiles, varargin)
            obj = obj@parallel.internal.mapreduce.AbstractTaskResult(varargin{:});
            if nargin
                obj.OutputFiles = outputFiles(:);
            end
        end
        
        % Combine several ReduceTaskResult instances together.
        function output = vertcat(varargin)
            import parallel.internal.mapreduce.ReduceTaskResult;
            
            outputFiles = cell(nargin, 1);
            for ii = 1:nargin
                nextResult = varargin{ii};
                if ~isempty(nextResult)
                    outputFiles{ii} = nextResult.OutputFiles;
                end
            end
            
            outputFiles = vertcat(outputFiles{:});
            [keyType, valueType] = combineTypes(varargin{:});
            
            output = ReduceTaskResult(outputFiles, keyType, valueType);
        end
    end
end
