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 Differentiator | |
import RxCocoa | |
import RxDataSources | |
import RxSwift | |
import UIKit | |
class RxTableViewSectionedUpdatingDataSource<S: AnimatableSectionModelType>: | |
TableViewSectionedDataSource<S>, RxTableViewDataSourceType { | |
typealias UpdateCell = (UITableViewCell, IndexPath, S.Item) -> Void | |
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 Array { | |
func quickSorted(_ areInIncreasingOrder: (Element, Element) -> Bool) -> Array { | |
guard count > 1, let lastElement = last else { return self } | |
var (preceding, successing) = (Array(), Array()) | |
dropLast().forEach { areInIncreasingOrder($0, lastElement) ? preceding.append($0) : successing.append($0) } | |
return preceding.quickSorted(areInIncreasingOrder) + [lastElement] + successing.quickSorted(areInIncreasingOrder) | |
} | |
} |
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]) } |
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
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 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
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
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
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 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 } | |
} | |
} |