diff --git a/Sources/MapLibreSwiftDSL/Data Sources.swift b/Sources/MapLibreSwiftDSL/Data Sources.swift index cf0edfb..561d20b 100644 --- a/Sources/MapLibreSwiftDSL/Data Sources.swift +++ b/Sources/MapLibreSwiftDSL/Data Sources.swift @@ -46,9 +46,33 @@ public struct ShapeSource: Source { @resultBuilder public enum ShapeDataBuilder { - public static func buildBlock(_ components: MLNShape...) -> ShapeData { - let features = components.compactMap({ $0 as? MLNShape & MLNFeature }) - + // Handle a single MLNShape element + public static func buildExpression(_ expression: MLNShape) -> [MLNShape] { + return [expression] + } + + public static func buildExpression(_ expression: [MLNShape]) -> [MLNShape] { + return expression + } + + // Combine elements into an array + public static func buildBlock(_ components: [MLNShape]...) -> [MLNShape] { + return components.flatMap { $0 } + } + + // Handle an array of MLNShape (if you want to directly pass arrays) + public static func buildArray(_ components: [MLNShape]) -> [MLNShape] { + return components + } + + // Handle for in of MLNShape + public static func buildArray(_ components: [[MLNShape]]) -> [MLNShape] { + return components.flatMap { $0 } + } + + // Convert the collected MLNShape array to ShapeData + public static func buildFinalResult(_ components: [MLNShape]) -> ShapeData { + let features = components.compactMap { $0 as? MLNShape & MLNFeature } if features.count == components.count { return .features(features) } else {