From 210d59e416dacf339b4d6d3e380f451bbc63dc94 Mon Sep 17 00:00:00 2001 From: Coen ten Thije Boonkkamp Date: Sat, 26 Jul 2025 16:09:04 +0200 Subject: [PATCH] Add Parse extension for conversion initializer This adds a convenience initializer to Parse that accepts a conversion and applies it to the rest of the input. This extension was originally in the URLRouting library but is better placed here as it's not specific to URL routing. --- Sources/Parsing/Conversion.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sources/Parsing/Conversion.swift b/Sources/Parsing/Conversion.swift index 6bc6500a4f..aac7c73773 100644 --- a/Sources/Parsing/Conversion.swift +++ b/Sources/Parsing/Conversion.swift @@ -26,3 +26,12 @@ /// - Returns: An "un"-transformed input value. func unapply(_ output: Output) throws -> Input } + +extension Parse { + @inlinable + public init( + _ conversion: Downstream + ) where Parsers == Parsing.Parsers.MapConversion, Downstream> { + self.init { Rest().map(conversion) } + } +}