Closed paulsamuels closed 6 years ago
Much neater! I've rebased the change and added the following
func postGenerationTextProcessing(options: Options) -> (_ source: String) -> Result<String, APIGeneratorError> {
var textProcessors: [TextProcessor] = [
RemoveSwiftOnoneSupport()
]
if options.noDocumentation {
textProcessors.append(RemoveComments())
}
return { source in
Result(attempt: { try textProcessors.reduce(source, { try $1.process(input: $0) }) }).mapError({ .failedToWrite(path: options.path, error: $0) })
}
}
return extractBuildArguments()
.flatMap(generateAPI)
.flatMap(postGenerationTextProcessing(options: options))
.flatMap(writeToFile(options: options))
More an experiment than anything but if this is reasonable then it might be worth changing to Result throughout and dropping
throw
as it's not very composableWhy: Having do/catch blocks all over the place can clutter things up and make it harder to see the control flow of data. The Result type has functions that allow for sequencing operations with a cleaner syntax whilst still propagating errors.
This change addresses the need by: Use Result rather that do/catch for sequencing the APIGeneration