This file contains 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
// | |
// Combine+WithLatestFrom.swift | |
// | |
// Created by Shai Mishali on 29/08/2019. | |
// Copyright © 2019 Shai Mishali. All rights reserved. | |
// | |
import Combine | |
// MARK: - Operator methods |
This file contains 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
// RxSwift signposts | |
import os.signpost | |
import RxSwift | |
func signpost<T>(log: OSLog, name: StaticString, value: String, _ thing: () throws -> T) rethrows -> T { | |
let signpostID = OSSignpostID(log: log) | |
os_signpost( | |
.begin, |
This file contains 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
/*: | |
This is a concept re-implementation of the @Binding and @State property wrappers from SwiftUI | |
The only purpose of this code is to implement those wrappers myself | |
just to understand how they work internally and why they are needed, | |
⚠️ This is not supposed to be a reference implementation nor cover all | |
subtleties of the real Binding and State types. | |
The only purpose of this playground is to show how re-implementing | |
them myself has helped me understand the whole thing better |
This file contains 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 typealias LosslessStringCodable = LosslessStringConvertible & Codable | |
public struct Value<T: LosslessStringCodable>: Codable { | |
private let type: LosslessStringCodable.Type | |
public var value: T | |
public init(from decoder: Decoder) throws { | |
do { | |
self.value = try T.init(from: decoder) |
This file contains 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 DictionaryEncoder { | |
init() { } | |
func encode(_ value: Encodable) throws -> [String: Any] { | |
let encoder = _Encoder(codingPath: []) | |
try value.encode(to: encoder) | |
guard let result = encoder.value as? [String: Any] else { | |
throw EncodingError.invalidValue(encoder.value as Any, .init(codingPath: [], debugDescription: "Invalid root container")) | |
} |
This file contains 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 Never { | |
/// A developer facing statement explaining how program correctness has failed. | |
public struct Reason: CustomStringConvertible { | |
public let description: String | |
public init(_ rationale: String) { | |
self.description = rationale | |
} | |
} | |
} |
This file contains 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
// | |
// TokenAcquisitionService.swift | |
// | |
// Created by Daniel Tartaglia on 16 Jan 2019. | |
// Copyright © 2022 Daniel Tartaglia. MIT License. | |
// | |
import Foundation | |
import RxSwift |
This file contains 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
func debounce<T>(delay: TimeInterval, function: @escaping (T) -> Void, complete: @escaping () -> Void = { }) -> (T) -> Void { | |
let queue = DispatchQueue(label: "Debouncer") | |
var current: DispatchWorkItem? | |
return { input in | |
current?.cancel() | |
let new = DispatchWorkItem { | |
function(input) | |
complete() | |
} |
This file contains 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 struct AnyCodable: Codable { | |
public let value: Any? | |
public init(_ value: Any?) { | |
self.value = value | |
} | |
public init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
This file contains 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 Validator where Input == User, Output == User { | |
static var validUser: Validator<User, User> { | |
return .keyPath(\.name, .isNotNil && .isNotEmpty) | |
} | |
} | |
struct User { | |
let name: String? | |
} |