From 0eca41946897c7fbf85aa3e38a160ffd427c6093 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 21 Sep 2015 15:41:01 -0400 Subject: [PATCH] Subscripting Prism by Int produces Prism. --- prototype/Doubt/JSON.swift | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/prototype/Doubt/JSON.swift b/prototype/Doubt/JSON.swift index 0dc52dde5..8d34e6fe2 100644 --- a/prototype/Doubt/JSON.swift +++ b/prototype/Doubt/JSON.swift @@ -73,6 +73,29 @@ extension Prism where To : DictionaryType { } } +protocol ArrayType { + typealias Element + + init(array: [Element]) + var array: [Element] { get } +} + +extension Array : ArrayType { + init(array: [Element]) { + self = array + } + + var array: [Element] { + return self + } +} + +extension Prism where To : ArrayType { + subscript (index: Int) -> Prism { + return self >>> Prism(forward: { $0.array[index] }, backward: { To(array: [ $0 ]) }) + } +} + private func toJSON(object: AnyObject) -> JSON? { struct E: ErrorType {} func die() throws -> T {