Skip to content

Instantly share code, notes, and snippets.

View tkersey's full-sized avatar
👹

Tim Kersey tkersey

👹
View GitHub Profile
@bkase
bkase / Component.swift
Created November 2, 2019 23:28
Comonadic UIs in SwiftUI with Bow
import Bow
import SwiftUI
public typealias Component<W: Comonad, V: View> =
Kind<W, SwiftUIBackendOf<CoOf<W, ()>, V>>
func const<A,B>(_ x: A) -> (B) -> A { return { _ in x } }
public final class ComponentView<W: Comonad, V: View>: View {
private var component: Component<W, V>
@ixrevo
ixrevo / RxFeedbackToComposableArchitectureAdapter.swift
Created April 7, 2020 10:48
Adapter to convert the RxFeedback reducer to ComposableArchitecture shape
import RxSwift
import RxFeedback
extension Observable where E == Any {
public static func system<State, Event, Environment>(
initialState: State,
reduce: @escaping (inout State, Event, Environment) -> [Effect<Event>],
scheduler: ImmediateSchedulerType,
environment: Environment,
feedback: [Feedback<State, Event>]
@inamiy
inamiy / ReplaceProps.ts
Created July 2, 2020 02:27
ReplaceProps in TypeScript
// https://stackoverflow.com/questions/53011500/how-to-replace-properties-using-mapped-types-in-typescript
// https://twitter.com/inamiy/status/1278511811025711104
type ReplaceProps<T, From, To> = {
[K in keyof T]: K extends keyof From
? T[K] extends From[K]
? K extends keyof To
? To[K]
: T[K]
: T[K]
@dabrahams
dabrahams / TypeErasureSurvey.swift
Last active August 29, 2020 15:28
Swift type erasure survey / performance analysis. Build with `swiftc -O -g -whole-module-optimization`
// Protocol to use for type erasure.
protocol Summable {
func sum() -> Int
}
// Concrete model. Type
extension Int: Summable {
func sum() -> Int { self }
}
extension Effect {
func cancellable<Id: Hashable>(id: Id) -> Effect<Output> {
return Deferred { () -> PassthroughSubject<Output, Failure> in
cancellables[id]?.cancel()
let subject = PassthroughSubject<Output, Failure>()
cancellables[id] = self.subscribe(subject)
return subject
}
.eraseToEffect()
}
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,
@Icelandjack
Icelandjack / Ran.markdown
Last active November 13, 2020 20:51
Right Kan extensions and Indexed Monads
@laser
laser / movie.md
Last active November 18, 2020 19:02

Movie Ticket Kata

First, head here to join our Zoom meeting. It will help me following along while you work through the assignment.

What Are We Building?

Write a program that calculates purchase price for movie tickets using any language you like. It should not be a full-blown web app; it can be a simple class or collection of methods invokable by your test suite. We'll provide you with some requirements, test-cases, and even a sample interface - all you have to do is give us some software.

Base Admission Rate

@ole
ole / NotificationObserver.swift
Last active February 17, 2021 16:34
Demo that retaining self in a NotificationCenter observer block leads to a reference cycle you have to break manually.
// Paste into a macOS playground in Xcode and run.
// Deleting line 46 "c?.stopObserving()" triggers the assertion because
// the reference cycle caused by retaining self in the observer block is never broken.
import Foundation
let myNotification = NSNotification.Name(rawValue: "myNotification")
var cHasBeenDeallocated = false
@IanKeen
IanKeen / AnyCodable.swift
Last active March 4, 2021 18:45
AnyCodable
public struct AnyCodable: Codable {
public let value: Any?
public init(_ value: Any?) {
self.value = value
}
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()