Skip to content

Commit 12b344b

Browse files
committed
Add a way to map a workflow's Never output type to a different type without generating compiler warnings.
1 parent 3fa55ff commit 12b344b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Workflow/Sources/AnyWorkflowConvertible.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,18 @@ struct OutputBlockingWorkflow<Child: AnyWorkflowConvertible>: Workflow {
147147
.rendered(in: context)
148148
}
149149
}
150+
151+
// MARK: -
152+
153+
extension AnyWorkflowConvertible where Output == Never {
154+
/// A convenience for workflows that don't produce output but want to change the declared output type.
155+
///
156+
/// This equivalent to `.mapOutput { switch $0 {} }` but avoids the compiler warning for unreachable code in the provided transform.
157+
public func mapOutput<NewOutput>() -> AnyWorkflow<Rendering, NewOutput> {
158+
asAnyWorkflow().mapOutput(silenceUnreachableWarning(_:))
159+
}
160+
161+
private func silenceUnreachableWarning<T>(
162+
_ input: Never
163+
) -> T { fatalError("unreachable") }
164+
}

0 commit comments

Comments
 (0)