Repository: vapor/vapor
File: Sources/Vapor/HTTP/Headers/HTTPHeaders+ContentRange.swift (Swift)

Code before:
        switch self {
            case .bytes:
                return "bytes"
            case .custom(let value):
                return value
        }
    }
}

public struct RangeHeader : Equatable {
    public let unit: RangeUnit
    public let ranges: [RequestedRange]
    
    public init(unit: RangeUnit, ranges: [RequestedRange]) {
        self.unit = unit
        self.ranges = ranges
    }
    
    public init?(requestHeader header: String) {
        let splitResult = header.split(separator: "=", omittingEmptySubsequences: false)
        guard splitResult.count == 2 else {
            return nil
        }
        let (unitStr, rangesStr) = (splitResult[0], splitResult[1])
        let ranges = rangesStr.split(separator: ",", omittingEmptySubsequences: false)
            .map { it in RequestedRange.from(requestStr: it) }
        if !ranges.filter({ $0 == nil }).isEmpty {
            return nil
        }
        let lowerCasedUnit = unitStr.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
        self.unit = lowerCasedUnit == "bytes"
            ? RangeUnit.bytes
            : RangeUnit.custom(value: lowerCasedUnit)
        self.ranges = ranges.compactMap { $0 }
    }
    
    func serialize() -> String {
        return "\(unit.serialize())=\(ranges.map { $0.serialize() }.joined(separator: ", "))"
    }
    
}

public struct ContentRangeHeader : Equatable {
    public let unit: RangeUnit
    public let range: ResponseContentRange
    
    public init(unit: RangeUnit, range: ResponseContentRange) {
        self.unit = unit
        self.range = range
    }
    

Review comment (suggestion):
```suggestion
            .map(RequestedRange.from)
```

Code after:
        case bytes
        case custom(value: String)
        
        public func serialize() -> String {
            switch self {
            case .bytes:
                return "bytes"
            case .custom(let value):
                return value
            }
        }
    }
    
    /// Represents the HTTP `Range` request header.
    /// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range
    public struct Range: Equatable {
        public let unit: RangeUnit
        public let ranges: [HTTPHeaders.Range.Value]
        
        public init(unit: RangeUnit, ranges: [HTTPHeaders.Range.Value]) {
            self.unit = unit
            self.ranges = ranges
        }
        
        init?(directives: [HTTPHeaders.Directive]) {
            let rangeCandidates: [HTTPHeaders.Range.Value] = directives.enumerated().compactMap {
                if $0.0 == 0, let parameter = $0.1.parameter {
                    return HTTPHeaders.Range.Value.from(requestStr: parameter)
                }
                return HTTPHeaders.Range.Value.from(requestStr: $0.1.value)
            }
            guard !rangeCandidates.isEmpty else {
                return nil
            }
            self.ranges = rangeCandidates
            let lowerCasedUnit = directives[0].value.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
            self.unit = lowerCasedUnit == "bytes"
                ? RangeUnit.bytes
                : RangeUnit.custom(value: lowerCasedUnit)
        }
        
        public func serialize() -> String {
            return "\(unit.serialize())=\(ranges.map { $0.serialize() }.joined(separator: ", "))"
        }
    }
    
    /// Represents the HTTP `Content-Range` response header.
    ///
    /// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range
    public struct ContentRange: Equatable {
        public let unit: RangeUnit