Skip to content

Instantly share code, notes, and snippets.


Tim Kersey tkersey

View GitHub Profile
tkersey / Validations.swift
Created Jun 29, 2020 — forked from lukeredpath/Validations.swift
A little experiment with functional Rails-style validators built on top of pointfreeco/Validated
View Validations.swift
import UIKit
import Validated
extension Validated {
func mapErrors<LocalError>(_ transform: (Error) -> LocalError) -> Validated<Value, LocalError> {
switch self {
case let .valid(value):
return .valid(value)
case let .invalid(errors):
return .invalid(
tkersey / Ran.markdown
Created Jun 18, 2020 — forked from Icelandjack/Ran.markdown
Right Kan extensions and Indexed Monads
View Ran.markdown
tkersey / AnimatableVector.swift
Created Jun 17, 2020 — forked from mecid/AnimatableVector.swift
High-performance Animatable Vector for SwiftUI
View AnimatableVector.swift
import SwiftUI
import enum Accelerate.vDSP
struct AnimatableVector: VectorArithmetic {
static var zero = AnimatableVector(values: [0.0])
static func + (lhs: AnimatableVector, rhs: AnimatableVector) -> AnimatableVector {
let count = min(lhs.values.count, rhs.values.count)
return AnimatableVector(values: vDSP.add(lhs.values[0..<count], rhs.values[0..<count]))
tkersey /
Created Jun 11, 2020 — forked from austinzheng/
Douglas Gregor's Swift Generics Manifesto, with added markdown formatting



The “Complete Generics” goal for Swift 3 has been fairly ill-defined thus fair, with just this short blurb in the list of goals:

Complete generics: Generics are used pervasively in a number of Swift libraries, especially the standard library. However, there are a number of generics features the standard library requires to fully realize its vision, including recursive protocol constraints, the ability to make a constrained extension conform to a new protocol (i.e., an array of Equatable elements is Equatable), and so on. Swift 3.0 should provide those generics features needed by the standard library, because they affect the standard library's ABI.

This message expands upon the notion of “completing generics”. It is not a plan for Swift 3, nor an official core team communication, but it collects the results of numerous discussions among the core team and Swift developers, both of the compiler an

tkersey / iOSCustomSegmentedControlSwiftUI.swift
Created Jun 5, 2020 — forked from frankfka/iOSCustomSegmentedControlSwiftUI.swift
Custom Segmented Picker / Segmented Control in SwiftUI
View iOSCustomSegmentedControlSwiftUI.swift
import SwiftUI
extension View {
func eraseToAnyView() -> AnyView {
struct SizePreferenceKey: PreferenceKey {
typealias Value = CGSize
tkersey / OffsetToPositionDemo.swift
Created May 27, 2020 — forked from CodeSlicing/OffsetToPositionDemo.swift
Demonstrates the use of offsetToPosition modifier
View OffsetToPositionDemo.swift
// OffsetToPositionDemo.swift
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
View boilerplate.swift
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI {
VStack {
Text("Hello, World")
View iOSActivityRingSwiftUI.swift
import SwiftUI
import PlaygroundSupport
extension Double {
func toRadians() -> Double {
return self * Double.pi / 180
func toCGFloat() -> CGFloat {
return CGFloat(self)
tkersey / Calendar.swift
Created May 6, 2020 — forked from mecid/Calendar.swift
Calendar view in SwiftUI
View Calendar.swift
import SwiftUI
fileprivate extension DateFormatter {
static var month: DateFormatter {
let formatter = DateFormatter()
formatter.dateFormat = "MMMM"
return formatter
static var monthAndYear: DateFormatter {
View function.swift
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,
You can’t perform that action at this time.