Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions NonEmptyArray/NonEmptyArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ extension NonEmptyArray: CustomDebugStringConvertible {
}
}

extension NonEmptyArray: Codable where Element : Codable {

public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
let array: [Element] = try values.decode([Element].self, forKey: .elements)
self.elements = array
}

private enum CodingKeys: String, CodingKey {
case elements
}
}

extension NonEmptyArray: Collection {
public typealias Index = Int

Expand Down