Skip to content

Instantly share code, notes, and snippets.

💭
🏔🏃‍♂

Rui Peres RuiAAPeres

💭
🏔🏃‍♂
Block or report user

Report or block RuiAAPeres

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View function.swift
public struct Function<Input, Output>: Identifiable {
public let id: String
private let f: (Input) -> Output
public init(
id: String,
f: @escaping (Input) -> Output
) {
self.id = id
View Injection.md
/// |                    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 / opaqueEquivalent.swift
Last active Feb 18, 2020
Extension to provide an equivalent opaque UIColor to a UIColor with alpha channel. So: f(r,g,b,a) == (r,g,b,1)
View opaqueEquivalent.swift
import UIKit
public extension UIColor {
var components: (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
var alpha: CGFloat = 0
@RuiAAPeres
RuiAAPeres / covariance_contravariance.swift
Last active Sep 16, 2019
Covariance and Contravariance in Swift
View covariance_contravariance.swift
import UIKit
// Based on https://www.stephanboyer.com/post/132/what-are-covariance-and-contravariance
// > Denotes "a subtype of"
// UIButton > UIView > UIResponder > NSObject
//
// e.g. `UIButton` is a subtype of `UIView`
//
// This means that any function that takes a `UIView`, can receive a `UIButton`:
//
@RuiAAPeres
RuiAAPeres / SwiftUIBindsWithReactiveSwift.swift
Last active Dec 20, 2019
Couple of methods to bridge ReactiveSwift with SwiftUI
View SwiftUIBindsWithReactiveSwift.swift
import Combine
import ReactiveSwift
import SwiftUI
class AnySubscription: Subscription {
private let cancelable: Cancellable
init(cancelable: Cancellable) {
self.cancelable = cancelable
View SwiftUI Property Delegates.swift
/// `ObjectBinding` used as a way to create a `Binding` from a `BindableObject`. In this case the ViewModel
/// complies with `BindableObject` which is then translated into a `Binding` which is what `Toggle` is expecting
/// NOTE: Since it's a `DynamicViewProperty`, after its value is changed, the body will be updated.
class ViewModel: BindableObject {
let didChange = PassthroughSubject<ViewModel, Never>()
var isEnabled = false {
didSet {
didChange.send(self)
View Flow_example.swift
public extension UIViewController {
var modalFlow: Flow {
return ModalFlow(self)
}
var navigationFlow: Flow {
guard let navigationController = self.navigationController else { return modalFlow }
return NavigationFlow(navigationController)
}
}
View phase3.swift
import Foundation
precedencegroup PipePrecedence {
associativity: left
higherThan: AssignmentPrecedence
}
infix operator |> : PipePrecedence
public func |> <T, U>(x: T, f: (T) -> U) -> U {
View phase2.swift
import Foundation
enum Result<T> {
case success(T)
case failure(String)
func map<U>(_ f: (T) -> U) -> Result<U> {
switch self {
case .success(let x): return .success(x |> f)
case .failure(let e): return .failure(e)
View phase1.swift
import Foundation
"4 5 + 3 +"
func calculator(_ input: String) -> Double {
return input |> split |> reversePolishNotation
}
func reversePolishNotation(_ input: [String]) -> Double {
var stack: [Double] = []
You can’t perform that action at this time.