From c28ee37f73f8fe894cd3161fe329ea373cc3eea7 Mon Sep 17 00:00:00 2001 From: Gordon Fontenot and Giles Van Gruisen Date: Fri, 25 Sep 2015 13:51:09 -0400 Subject: [PATCH] Extend CollectionType intead of extending Array Extending Array was great, but it'd be nicer if we could extend _any_ collection type that contains Decodable objects. This `decode` function will still always return an Array, for the same reason that the stdlib's `map`, `flatMap`, etc return Arrays, but if we ever get Real Actual Higher Kinded Types, we can fix this. --- Argo/Types/StandardTypes.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Argo/Types/StandardTypes.swift b/Argo/Types/StandardTypes.swift index 98556e0..82aaac9 100644 --- a/Argo/Types/StandardTypes.swift +++ b/Argo/Types/StandardTypes.swift @@ -60,10 +60,10 @@ public extension Optional where Wrapped: Decodable, Wrapped == Wrapped.DecodedTy } } -public extension Array where Element: Decodable, Element == Element.DecodedType { - static func decode(j: JSON) -> Decoded<[Element]> { +public extension CollectionType where Generator.Element: Decodable, Generator.Element == Generator.Element.DecodedType { + static func decode(j: JSON) -> Decoded<[Generator.Element]> { switch j { - case let .Array(a): return sequence(a.map(Element.decode)) + case let .Array(a): return sequence(a.map(Generator.Element.decode)) default: return .typeMismatch("Array", actual: j) } }