-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQLPath.swift
45 lines (35 loc) · 1.46 KB
/
QLPath.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
open class QLPath<Input, Output> {
public typealias Operation = QLSegment<Input, Output>.Operation
public typealias Completion = QLSegment<Input, Output>.Completion
public required init?(_ segments: AnySegment...) {
guard
let lastSegment = segments.last,
let firstSegment = segments.first
else { return nil }
do {
let _: AnySegment =
try segments.reduce(
firstSegment,
({ result, next in
guard (result !== next) else { return result }
guard let _ = result.linked(to: next)
else { throw QLCommon.Error.AnchorMismatch }
return next
})
)
lastSegment.applyOutputAnchor(self.output)
self.input = firstSegment.inputAnchor as! QLAnchor<Input>
} catch { return nil }
}
public final var input: QLAnchor<Input> = QLAnchor<Input>()
public final var output: QLAnchor<Output> = QLAnchor<Output>()
public final func findSegments(with operationId: AnyHashable) -> [AnySegment] {
return output.inputSegment?.findSegments(with: operationId) ?? []
}
public final func describeOperationPath() -> String {
return output.inputSegment?.describeOperationPath() ?? ""
}
public final func operationPath() -> QLoopOperationPath {
return output.inputSegment?.operationPath() ?? []
}
}