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
// | |
// Redux.playground | |
// | |
// Created by Felix Mau on 25.06.20. | |
// Copyright © 2020 Felix Mau. All rights reserved. | |
// | |
import PlaygroundSupport | |
import SwiftUI |
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-PassthroughSubject-CurrentValueSubject.playground | |
// | |
// Created by Felix Mau on 30.07.20. | |
// Copyright © 2020 Felix Mau. All rights reserved. | |
// | |
import PlaygroundSupport | |
import Combine |
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 Collection { | |
/// Returns an array of subsequences of maximum size `chunkSize`. | |
/// | |
/// For example: | |
/// | |
/// // ["ABCD", "EFGH", "IJ"] | |
/// "ABCDEFGHIJ".split(chunkSize: 4) | |
/// | |
/// - parameter chunkSize: the maximum size of the returned subsequences. | |
/// - precondition: chunkSize > 0 |
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
import Foundation | |
/// To create an operation: | |
/// | |
/// 1. Subclass AsynchronousOperation, override main, and eventually cancel the | |
/// operation, or set result to a non-nil value. | |
/// | |
/// 2. Use makeOperation { op in ... }, and eventually cancel the | |
/// operation, or set result to a non-nil value. | |
open class AsynchronousOperation<Output, Failure: Error>: Operation { |
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
import Combine | |
import Foundation | |
func loadNewsTitles() -> AnyPublisher<[String], Never> { | |
["title1", "title2"] | |
.publisher | |
.delay(for: .microseconds(500), scheduler: DispatchQueue.main) | |
.collect() | |
.eraseToAnyPublisher() | |
} |
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 heavily based on the work done at RxGRDB | |
import GRDB | |
import ReactiveSwift | |
extension DatabasePool: ReactiveExtensionsProvider {} | |
extension DatabaseQueue: ReactiveExtensionsProvider {} | |
extension ValueObservation: ReactiveExtensionsProvider {} | |
extension DatabaseRegionObservation: ReactiveExtensionsProvider {} |
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
// Run any SwiftUI view as a Mac app. | |
import Cocoa | |
import SwiftUI | |
NSApplication.shared.run { | |
VStack { | |
Text("Hello, World") | |
.padding() | |
.background(Capsule().fill(Color.blue)) |
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
import Foundation | |
import class UIKit.UIImage | |
struct AttributedString: ExpressibleByStringInterpolation { | |
enum Attribute: Hashable { | |
enum ImportanceLevel: String, Equatable { | |
case very | |
case enough | |
} | |
case important(ImportanceLevel = .enough) |
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
import PlaygroundSupport | |
import Foundation | |
class WeakRef<T> where T: AnyObject { | |
private(set) weak var value: T? | |
init(value: T?) { | |
self.value = value | |
} |
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
import Combine | |
import Foundation | |
/// A thread-safe store for cancellables which addresses usability pain points | |
/// with stock Combine apis. | |
/// | |
/// ## Thread-safe storage of cancellables | |
/// | |
/// let cancelBag = CancelBag() | |
/// cancellable.store(in: cancelBag) |