/// | World |
/// |------------------------------------------|
/// | Module A | Module B | Module C | Module D|
- World is a module
- World is aware of all modules.
- Modules aren't aware of World.
| // | |
| // DON'T do this, or else you risk a deadlock (e.g., by accidentally performing it in a different order somewhere) | |
| // | |
| dispatch_async(firstQueue, ^{ | |
| dispatch_sync(secondQueue, ^{ | |
| // code requiring both queues | |
| }); | |
| }); |
| extension Collection where SubSequence: Sequence, SubSequence.Iterator.Element == Iterator.Element { | |
| func cut(atSuccession shouldCut: (Iterator.Element, Iterator.Element) throws -> Bool) rethrows -> [Self.SubSequence] { | |
| var (fromIndex, toIndex) = (startIndex, startIndex) | |
| var result: [SubSequence] = [] | |
| for (x, y) in zip(self, dropFirst()) { | |
| defer { toIndex = index(after: toIndex) } | |
| guard try shouldCut(x, y) else { continue } | |
| result.append(self[fromIndex...toIndex]) | |
| fromIndex = index(after: toIndex) | |
| } |
| #!/usr/bin/swift | |
| import AppKit | |
| // MARK: - Helpers | |
| @inline(__always) func error(_ message: String) { | |
| print("💥 \(message)") | |
| } | |
| @inline(__always) func success(_ message: String) { |
/// | World |
/// |------------------------------------------|
/// | Module A | Module B | Module C | Module D|