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 | |
| class StreamReader { | |
| let encoding: String.Encoding | |
| let chunkSize: Int | |
| let fileHandle: FileHandle | |
| var buffer: Data | |
| let delimPattern : Data | |
| var isAtEOF: Bool = false | |
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 ReactiveCocoa | |
| import ReactiveSwift | |
| extension SignalProducer { | |
| func result() -> SignalProducer<Result<Value, Error>, Never> { | |
| return map(Swift.Result<Value, Error>.success) | |
| .flatMapError { SignalProducer<Result<Value, Error>, Never>(value: .failure($0)) } | |
| } | |
| } |
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
| public protocol EitherProtocol { | |
| associatedtype Left | |
| associatedtype Right | |
| var either: Either<Left, Right> { get } | |
| } | |
| public enum Either<Left, Right> { | |
| case left(Left) | |
| case right(Right) |
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
| public protocol ResultProtocol { | |
| associatedtype Success | |
| associatedtype Failure: Error | |
| var result: Result<Success, Failure> { get } | |
| } | |
| extension Result: ResultProtocol { | |
| public var result: Result<Success, Failure> { | |
| return 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
| #if canImport(Foundation) && canImport(Accelerate) | |
| import Foundation | |
| import Accelerate | |
| extension la_object_t { | |
| public var rows: UInt { la_matrix_rows(self) } | |
| public var cols: UInt { la_matrix_cols(self) } | |
| public func array1D() -> [Double] { |
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
| /// | |
| /// ```swift | |
| /// let fibonacci = memoize { (function: (Int) -> Int, n: Int) -> Int in | |
| /// if n < 2 { | |
| /// return n | |
| /// } | |
| /// return function(n - 1) + function(n - 2) | |
| /// } | |
| /// ``` | |
| /// |
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 SwiftUI | |
| import enum Accelerate.vDSP | |
| public struct AnimatableVector<V: BinaryFloatingPoint>: VectorArithmetic, Hashable { | |
| public var values: [Double] | |
| public init<V: BinaryFloatingPoint>(values: [V]) { | |
| self.values = values.map(Double.init) | |
| } |
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
| public final class ViewController: UIViewController { | |
| private lazy var myView = MyView() | |
| public override func viewDidLoad() { | |
| super.viewDidLoad() | |
| view.addSubview(myView) | |
| myView.translatesAutoresizingMaskIntoConstraints = false | |
| NSLayoutConstraint.activate(myView, view) { content, parent in |
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
| class FlowLayoutHorizontalLeft: UICollectionViewFlowLayout { | |
| private var cache: [IndexPath: UICollectionViewLayoutAttributes] = [:] | |
| override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { | |
| super.layoutAttributesForElements(in: rect)? | |
| .lazy | |
| .filter { $0.representedElementCategory == .cell } | |
| .map { self.layoutAttributesForItem(at: $0.indexPath) } | |
| .compactMap { $0 } |
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 UIKit | |
| extension UITableView { | |
| func register(_ type: UITableViewCell.Type, identifier: String? = nil) { | |
| self.register(type, forCellReuseIdentifier: identifier ?? String(describing: type)) | |
| } | |
| func register(@ArrayBuilder<UITableViewCell.Type> builder: () -> [UITableViewCell.Type]) { | |
| builder().forEach { type in | |
| register(type) |
OlderNewer