This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Stack<Element> { | |
| fileprivate class Node { | |
| let value: Element | |
| var previousNode: Node? | |
| init(_ value: Element, previousNode: Node?) { | |
| self.value = value | |
| self.previousNode = previousNode | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct DoublyLinkedList<Element> { | |
| class Node { | |
| var value: Element | |
| weak var next: Node? | |
| var previous: Node? | |
| init(_ value: Element, next: Node?, previous: Node?) { | |
| (self.value, self.next, self.previous) = (value, next, previous) | |
| next?.previous = self | |
| previous?.next = self |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension RandomAccessCollection { | |
| func stableSorted(by areInIncreasingOrder: (Self.Element, Self.Element) -> Bool) -> [Self.Element] { | |
| return enumerated() | |
| .sorted { first, second in | |
| return areInIncreasingOrder(first.element, second.element) || first.offset < second.offset | |
| } | |
| .map { $0.element } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SnapKit | |
| struct ConstraintSwitcher { | |
| private var initialActive = [Constraint]() | |
| private var initialInactive = [Constraint]() | |
| private(set) var isInitialActive = true | |
| mutating func append(_ constraint: Constraint, active: Bool) { | |
| if active == isInitialActive { | |
| initialActive.append(constraint) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Dictionary { | |
| func flatMapValues<T>(_ transform: (Value) throws -> T?) rethrows -> [Key: T] { | |
| return try reduce(into: [:]) { $0[$1.key] = try transform($1.value) } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Sequence { | |
| func toDictionary<T: Hashable>(_ keyTransformer: (Element) throws -> T) rethrows -> Dictionary<T, Element> { | |
| return try reduce(into: [:]) { try $0[keyTransformer($1)] = $1 } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import RxSwift | |
| protocol Dispatchable {} | |
| protocol DispatchableElement {} | |
| extension PublishSubject: Dispatchable where E: DispatchableElement {} | |
| final class EventDispatcher { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| final class XMLElementExtractor: NSObject, XMLParserDelegate { | |
| private var isTarget = false | |
| private var value: String? | |
| private let elementName: String | |
| private init(elementName: String) { | |
| self.elementName = elementName | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| public enum JSON : Codable { | |
| case null | |
| case boolean(Bool) | |
| case number(Double) | |
| case string(String) | |
| case array([JSON]) | |
| case dictionary([String : JSON]) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct SubtitleEntry { | |
| let index: Int | |
| let startTime, endTime: TimeInterval | |
| let text: String | |
| } | |
| extension String { | |
| subscript(nsrange: NSRange) -> String? { | |
| return Range(nsrange, in: self) | |
| .flatMap { range in String(self[range]) } |
OlderNewer