1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00

Pass updates to collections along correctly.

This commit is contained in:
Rob Rix 2015-11-05 11:45:46 -05:00
parent 59e02988f0
commit 917a49c520

View File

@ -91,7 +91,7 @@ public struct Location<A>: SequenceType {
// MARK: - Implementation details
private init?<C: MutableCollectionType where C.Generator.Element == A, C.Index: BidirectionalIndexType>(_ weave: (A -> Location?) -> A -> Location?, _ up: C -> Location?, _ ts: C) {
func update(index: C.Index)(_ f: C -> Location?)(_ a: A) -> Location? {
func update(index: C.Index, _ ts: C)(_ f: C -> Location?)(_ a: A) -> Location? {
guard ts.indices.contains(index) else { return nil }
var copy = ts
copy[index] = a
@ -99,7 +99,7 @@ public struct Location<A>: SequenceType {
}
func into(index: C.Index)(_ ts: C) -> Location? {
guard ts.indices.contains(index) else { return nil }
return Location(it: ts[index], down: weave(update(index)(into(index))), up: update(index)(up), left: update(index)(into(index.predecessor())), right: update(index)(into(index.successor())))
return Location(it: ts[index], down: weave(update(index, ts)(into(index))), up: update(index, ts)(up), left: update(index, ts)(into(index.predecessor())), right: update(index, ts)(into(index.successor())))
}
guard let location = into(ts.startIndex)(ts) else { return nil }
self = location