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
@resultBuilder | |
public struct ArrayBuilder<Element> { | |
public static func buildPartialBlock(first: Element?) -> [Element] { first.map { [$0] } ?? [] } | |
public static func buildPartialBlock(first: [Element]?) -> [Element] { first ?? [] } | |
public static func buildPartialBlock(first: [Element?]?) -> [Element] { (first ?? []).compactMap { $0 } } | |
public static func buildPartialBlock(accumulated: [Element], next: Element?) -> [Element] { accumulated + (next.map { [$0] } ?? []) } | |
public static func buildPartialBlock(accumulated: [Element], next: [Element]?) -> [Element] { accumulated + (next ?? []) } | |
public static func buildPartialBlock(accumulated: [Element], next: [Element?]?) -> [Element] { accumulated + (next ?? []).compactMap { $0 } } | |
// Empty Case |
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
[ | |
[ | |
{ | |
"a": 7 | |
}, | |
"", | |
"", | |
{ | |
"x": 0.25, | |
"a": 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
@propertyWrapper | |
public struct Proxy<EnclosingSelf, Value> { | |
private let keyPath: ReferenceWritableKeyPath<EnclosingSelf, Value> | |
public init(_ keyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>) { | |
self.keyPath = keyPath | |
} | |
@available(*, unavailable) | |
public var wrappedValue: 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 RxSwift | |
// concept from RxSwiftExt | |
public enum RetryInterval { | |
case immediate(count: Int) | |
case delayed(count: Int, interval: DispatchTimeInterval) | |
case exponential(count: Int, initial: DispatchTimeInterval, multiplier: Int) | |
case custom(count: Int, delayCalculator: (Int) -> DispatchTimeInterval) | |
var intervals: [DispatchTimeInterval] { |
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 | |
/// RepeatingTimer mimics the API of DispatchSourceTimer but in a way that prevents | |
/// crashes that occur from calling resume multiple times on a timer that is | |
/// already resumed (noted by https://github.com/SiftScience/sift-ios/issues/52 | |
class RepeatingTimer { | |
// MARK: State | |
private enum State { | |
case suspended | |
case resumed |