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
private let state: BehaviorRelay<String> = .init(value: "!!!") | |
... | |
public func doSomething() -> Observable<String> { | |
... |
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
static func update(event: Event, context: Context) -> Async<Model> { | |
async { yield in | |
switch event { | |
case .increase: | |
context.countRepository.increase() | |
case .increaseAutomatically: | |
yield(context.countRepository.increaseAutomatically(interval: 2.0, until: context.until) | |
.flatMap { self.makeModelAsync(context: context) }) | |
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 Combine | |
public func async<T>(_ body: @escaping (Yield<T>) throws -> ()) -> Async<T> { | |
Async(body: body) | |
} | |
public func await<P>(_ publisher: P) throws -> P.Output where P: Publisher { | |
try publisher.await() | |
} |
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
@propertyWrapper | |
class YORO<T> { | |
private var value: T? | |
var wrappedValue: T? { | |
get { | |
let result = value | |
value = .none | |
return result | |
} | |
set { |
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 protocol OptionalType { | |
associatedtype Wrapped | |
var optional: Wrapped? { get } | |
} | |
extension Optional: OptionalType { | |
public var optional: Wrapped? { 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 UIKit | |
public typealias Send<A> = (A) -> () | |
public typealias Receive<A> = (A) -> () | |
public typealias Observe<A> = (@escaping Receive<A>) -> (ObserveToken) | |
public typealias OPipe<A> = (send: Send<A>, observe: Observe<A>) | |
public class ObserveToken: Hashable { | |
let uuid = UUID() | |
let receive: Any |
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
let i = 1 | |
let ii = 2 | |
// let flag = i < ii | |
// if flag {} | |
if (flag: i < ii).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
extension DispatchQueue { | |
func debounce(interval: DispatchTimeInterval) -> (_ exec: @escaping () -> ()) -> DispatchSourceTimer? { | |
var timer: DispatchSourceTimer? | |
return { [weak self] exec in | |
timer?.cancel() | |
timer = DispatchSource.makeTimerSource(queue: self) | |
timer?.setEventHandler(handler: exec) | |
timer?.schedule(deadline: .now() + interval, repeating: .infinity) |
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
let range = 0..<10000000 | |
var i = false | |
test("for in") { | |
for n in range { | |
i = i || (n % 12345 == 0) | |
} | |
} | |
print(String(i)) |
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
let range = 0..<10000000 | |
var i = [Int]() | |
test("for in") { | |
for n in range { | |
i.append(n) | |
} | |
} | |
print(String(i.count)) |