Skip to content

Instantly share code, notes, and snippets.

:octocat:

Tim Kersey tkersey

:octocat:
View GitHub Profile
@tkersey
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(errors.map(transform))
@tkersey
tkersey / Ran.markdown
Created Jun 18, 2020 — forked from Icelandjack/Ran.markdown
Right Kan extensions and Indexed Monads
View Ran.markdown
@tkersey
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
tkersey / generics_manifesto.md
Created Jun 11, 2020 — forked from austinzheng/generics_manifesto.md
Douglas Gregor's Swift Generics Manifesto, with added markdown formatting
View generics_manifesto.md

(Source: https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160229/011666.html)

Introduction

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
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 {
AnyView(self)
}
}
struct SizePreferenceKey: PreferenceKey {
typealias Value = CGSize
@tkersey
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
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
View iOSActivityRingSwiftUI.swift
import SwiftUI
import PlaygroundSupport
extension Double {
func toRadians() -> Double {
return self * Double.pi / 180
}
func toCGFloat() -> CGFloat {
return CGFloat(self)
@tkersey
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.