Skip to content

Instantly share code, notes, and snippets.

View RuiAAPeres's full-sized avatar
💭
🏔🏃‍♂️

Rui Peres RuiAAPeres

💭
🏔🏃‍♂️
View GitHub Profile
struct MyModelDTO {
let property1: Type1
let property2: Type2
}
extension MyModelDTO {
init(model: MyModel_CoreData) {
self.init(property1: model.property1, property2: model.property2)
}
}
public typealias CompletionHandler = Function<Void, Void>
public typealias SideEffect<Input> = Function<Input, Void>
public struct Function<Input, Output>: Identifiable {
public let id: String
internal let f: (Input) -> Output
public init(
id: String,
import Foundation
@propertyWrapper struct Notifier<Value> {
private let identifier: String
var wrappedValue: Value? {
didSet {
NotificationCenter.default.post(name: Notification.Name(identifier), object: wrappedValue)
}
}
@RuiAAPeres
RuiAAPeres / SwiftUIBindsWithReactiveSwift.swift
Last active December 12, 2023 09:30
Couple of methods to bridge ReactiveSwift with SwiftUI
import Combine
import ReactiveSwift
import SwiftUI
class AnySubscription: Subscription {
private let cancelable: Cancellable
init(cancelable: Cancellable) {
self.cancelable = cancelable
Task { @MainActor in
}
// let base = [1,2,4,6,5,8,6]
// let filtered = base.takeUntil{ $0.isMultiple(of: 2) } // [2,4,6]
//
// let base = [2,4,6,5,8,6]
// let filtered = base.takeUntil{ $0.isMultiple(of: 2) } // [2,4,6]
//
// It stops collecting when the predicate fails (5,8,6 are not evaluated)
//
// Idea by https://twitter.com/K0nserv
//
/// |                    World                 |
/// |------------------------------------------|
/// | Module A | Module B | Module C | Module D|
  1. World is a module
  2. World is aware of all modules.
  3. Modules aren't aware of World.
@RuiAAPeres
RuiAAPeres / reactiveswift+grdb.swift
Last active August 30, 2021 17:24
ReactiveSwift extensions for GRDB
/// 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 {}
public typealias CompletionHandler = Function<Void, Void>
public typealias SideEffect<Input> = Function<Input, Void>
public struct Function<Input, Output>: Identifiable {
public let id: String
internal let f: (Input) -> Output
public init(
id: String,
@RuiAAPeres
RuiAAPeres / Assertion+ReactiveSwift.swift
Last active August 5, 2020 10:46
Unit Testing ReactiveSwift streams with Assertions (idea by @andersio)
import ReactiveSwift
import XCTest
private let counterFailure: (Int, Int) -> String = { count, maxCount in
return "Counter is currently at \(count) which higher than the max \(maxCount)"
}
private let timeoutFailure = "Expectation timeout"
private let infoTemplate: (String, String, Int) -> String = { fileName, functionName, lineNumber in