Skip to content

Instantly share code, notes, and snippets.

@sergdort
sergdort / TaskPublisher.swift
Last active June 12, 2021 11:51
Bridge between async await and Publisher.
@available(iOS 15.0, *)
struct TaskPublisher<Output>: Publisher{
typealias Failure = Never
let work: () async -> Output
init(work: @escaping () async -> Output) {
self.work = work
}
@sergdort
sergdort / Iff.swift
Created June 16, 2019 22:50
Iff and Some operators for #SwiftUI. Inspired on some stuff we use in [Bento](). It lets you chain modifiers instead of doing "if - else" dance 🚀
extension View {
func iff(_ condition: Bool, _ modifier: (Self) -> AnyView) -> AnyView {
if condition {
return modifier(self).eraseToAnyView()
}
return eraseToAnyView()
}
func some<Value>(_ optional: Value?, modifier: (Value, Self) -> AnyView) -> some View {
guard let value = optional else {

iOS Astronauts Code of Conduct

iOS Astronauts is dedicated to providing a harassment-free community for everyone, regardless of sex, gender identity or expression, sexual orientation, disability, physical appearance, age, body size, race, nationality, or religious beliefs. We do not tolerate harassment of community members in any form. Participants violating these rules may be sanctioned or expelled from the community at the discretion of the organizers.

Harassment includes offensive verbal or written comments related to sex, gender identity or expression, sexual orientation, disability, physical appearance, age, body size, race, nationality, or religious beliefs, deliberate intimidation, threats, stalking, following, harassing photography or recording, sustained disruption of talks or other events, inappropriate physical contact, and unwelcome sexual attention. Sexual language and imagery is not appropriate for any iOS Astronauts event or communication channel. Community members asked to stop any harass

public class Observable<Element>: ObservableType {
public typealias E = Element
private let _subscribeHandler: (Observer<Element>) -> Disposable
public init(_ subscribtionClosure: @escaping (Observer<Element>) -> Disposable) {
_subscribeHandler = subscribtionClosure
}
public func subscribe<O : ObserverType>(observer: O) -> Disposable where O.E == E {
let sink = Sink(forvard: observer, subscribtionHandler: _subscribeHandler)
public class Observable<Element>: ObservableType {
public typealias E = Element
private let _subscribeHandler: (Observer<Element>) -> Disposable
public init(_ subscribtionClosure: @escaping (Observer<Element>) -> Disposable) {
_subscribeHandler = subscribtionClosure
}
public func subscribe<O : ObserverType>(observer: O) -> Disposable where O.E == E {
let composite = CompositeDisposable()
public final class Observer<E>: ObserverType {
private let _handler: (Event<E>) -> Void
public init(handler: @escaping (Event<E>) -> Void) {
_handler = handler
}
public func on(event: Event<E>) {
_handler(event)
}
public final class AnonimousDisposable: Disposable {
private let _disposeHandler: () -> Void
public init(_ disposeClosure: @escaping () -> Void) {
_disposeHandler = disposeClosure
}
public func dispose() {
_disposeHandler()
}
public protocol Disposable {
func dispose()
}
public protocol ObserverType {
associatedtype E
func on(event: Event<E>)
}
public enum Event<T> {
case next(T)
case error(Error)
case completed
extension ObservableType {
public func map<U>(_ transform: @escaping (E) throws -> U) -> Observable<U> {
return Observable<U> { observer in
return self.subscribe(observer: Observer { (event) in
switch event {
case .next(let element):
do {
try observer.on(event: .next(transform(element)))
} catch {
observer.on(event: .error(error))