in src/plugins/algebraic-type-matching-generic.ts [92:132]
function genericMatchingCodeForAlgebraicType(
algebraicType: AlgebraicType.Type,
): string[] {
const localVariableDeclaration: string[] = ['__block id result = nil;', ''];
const matchingBlockCode: string[] = algebraicType.subtypes.reduce(
(soFar, subtype) =>
buildLocalFunctionBlockDefinitionsForSubtype(
algebraicType,
soFar,
subtype,
),
[],
);
const keywordPartsForMatchInvocation: string[] =
algebraicType.subtypes.reduce(
(soFar, subtype, idx) =>
AlgebraicTypeUtilsForMatching.buildKeywordPartsForInvokingMatchMethodForSubtype(
algebraicType,
soFar,
subtype,
idx,
),
[],
);
const matchInvocation: string[] = [
'[' +
parameterNameForAlgebraicType(algebraicType) +
' ' +
keywordPartsForMatchInvocation.join(' ') +
'];',
];
const returnStatement: string[] = ['', 'return result;'];
return localVariableDeclaration
.concat(matchingBlockCode)
.concat(matchInvocation)
.concat(returnStatement);
}