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
var greeting: String? = "Hello, playground" | |
class Wrapper<T> { | |
var value: T | |
init(initialValue: T) { | |
self.value = initialValue | |
} | |
func transform<V>(_ transform: (T) -> V) -> V { |
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
[ | |
[ | |
{ | |
"a": 7 | |
}, | |
"", | |
"", | |
{ | |
"x": 0.25, | |
"a": 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
struct NotePage { | |
var title: String | |
var contents: String | |
} | |
class NoteCover { | |
var page: NotePage | |
init(page: NotePage) { | |
self.page = page |
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
protocol Enumable { | |
static func integerHolder(_: Int) -> Self | |
} | |
// SE-0280 | |
enum Value: Enumable { | |
case integerHolder(Int) | |
} | |
let someValue = Value.integerHolder(1) |
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 UIKit | |
import Combine | |
class Store<Action: Equatable, State> { | |
var action = PassthroughSubject<Action, Never>() | |
private var cancelBag = Set<AnyCancellable>() | |
private var reducers: [(Action, State) -> State] | |
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 Array { | |
func mutateMap(_ transform: (inout Element) throws -> Void) rethrows -> Self { | |
var copy = self | |
for (index, _) in copy.enumerated() { | |
try transform(©[index]) | |
} | |
return copy | |
} | |
func mutateMap<T>(_ keyPath: WritableKeyPath<Element, T>, _ value: T) -> Self { | |
var copy = self |
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 RxSwift | |
extension ObservableType { | |
public static func concatEager<S: Sequence>(_ sequence: S) -> Observable<Self.Element> | |
where S.Element == Observable<Self.Element> { | |
let multicastedObservables = sequence.map { | |
$0.multicast(ReplaySubject.createUnbounded()) | |
} | |
var disposables: [Disposable] = [] | |
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 RxSwift | |
let dispatchQueScheduler = ConcurrentDispatchQueueScheduler(qos: .background) | |
let observable1 = Observable<Int> | |
.just(1) | |
.do( | |
onSubscribe: { print("observable1 subscribed") }, | |
onDispose: { print("observable1 disposed") } | |
) |
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 RxCocoa | |
@propertyWrapper | |
struct Behavior<T> { | |
private var relay: BehaviorRelay<T> | |
var wrappedValue: T { | |
get { self.relay.value } | |
set { self.relay.accept(newValue) } | |
} |
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 | |
@propertyWrapper | |
struct Converted<T: Decodable, U: RawRepresentable>: Decodable where T == U.RawValue { | |
private let baseValue: T | |
var wrappedValue: U? { U(rawValue: baseValue) } | |
var projectedValue: T { baseValue } | |
init(from decoder: Decoder) throws { |