mirror of
https://github.com/zhigang1992/Argo.git
synced 2026-05-26 18:43:08 +08:00
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.
This commit is contained in:
committed by
Tony DiPasquale
parent
ec1ad342b3
commit
c28ee37f73
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user