mirror of
https://github.com/github/semantic.git
synced 2024-12-24 23:42:31 +03:00
Correct the index semantics for keyed explorations.
This commit is contained in:
parent
07fdfc5abc
commit
db616e1dfe
@ -106,16 +106,16 @@ public struct Location<A>: SequenceType {
|
||||
}
|
||||
|
||||
private init?<C: MutableCollectionType, Key where C.Generator.Element == (Key, A), C.Index: BidirectionalIndexType>(_ weave: (A -> Location?) -> A -> Location?, _ up: C -> Location?, _ ts: C) {
|
||||
func update(index: C.Index)(_ f: C.Index -> C -> Location?)(_ key: Key)(_ a: A) -> Location? {
|
||||
func update(index: C.Index)(_ f: C -> Location?)(_ key: Key)(_ a: A) -> Location? {
|
||||
guard ts.indices.contains(index) else { return nil }
|
||||
var copy = ts
|
||||
copy[index] = (key, a)
|
||||
return f(index)(copy)
|
||||
return f(copy)
|
||||
}
|
||||
func into(index: C.Index)(_ ts: C) -> Location? {
|
||||
guard ts.indices.contains(index) else { return nil }
|
||||
let (key, value) = ts[index]
|
||||
return Location(it: value, down: weave(update(index)(into)(key)), up: update(index)(const(up))(key), left: update(index.predecessor())(into)(key), right: update(index.successor())(into)(key))
|
||||
return Location(it: value, down: weave(update(index)(into(index))(key)), up: update(index)(up)(key), left: update(index)(into(index.predecessor()))(key), right: update(index)(into(index.successor()))(key))
|
||||
}
|
||||
guard let location = into(ts.startIndex)(ts) else { return nil }
|
||||
self = location
|
||||
|
Loading…
Reference in New Issue
Block a user