Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Tim Kersey tkersey

:octocat:
View GitHub Profile
View Prelude.swift
// MARK: - Precedence
precedencegroup ForwardApplication {
associativity: left
higherThan: AssignmentPrecedence
}
precedencegroup ForwardComposition {
associativity: left
higherThan: ForwardApplication
}
View Weak.swift
func weak<T: AnyObject, U>(_ obj: T, in f: @escaping (T) -> (U) -> Void) -> (U) -> Void {
return { [weak obj] u in
guard let obj = obj else { return }
f(obj)(u)
}
}
@tkersey
tkersey / PolyLens.hs
Created Oct 7, 2020 — forked from ekmett/PolyLens.hs
Towards poly-kinded optics (fusing multiplate and lens)
View PolyLens.hs
{-# language DataKinds #-}
{-# language PolyKinds #-}
{-# language RankNTypes #-}
{-# language ConstraintKinds #-}
{-# language DeriveFunctor #-}
{-# language GADTs #-}
{-# language TypeApplications #-}
{-# language ScopedTypeVariables #-}
{-# language FlexibleInstances #-}
{-# language FlexibleContexts #-}
@tkersey
tkersey / Mocks.md
Last active Oct 5, 2020
Sourcery based mocking
View Mocks.md

Mocks for testing

To mock a particular protocol, make it extend to Mockable.

brew install soucery

// from the root of this repo
sourcery --sources Foo --templates sourcery/mockable.stencil --output FooTests/Mocks
@tkersey
tkersey / Regex.swift
Created Aug 6, 2020
Regex.swift (without NSRegularExpression)
View Regex.swift
import Foundation
extension String {
public func matches(regex: String) -> Bool {
guard let range = range(of: regex, options: .regularExpression, range: nil, locale: nil) else { return false }
return range.lowerBound == startIndex && range.upperBound == endIndex
}
public func doesNotMatch(regex: String) -> Bool {
range(of: regex, options: .regularExpression, range: nil, locale: nil) == nil
@tkersey
tkersey / Example1.swift
Created Jul 22, 2020 — forked from dabrahams/Example1.swift
Ambiguity problems with giving generic types the right behavior with conditional conformances
View Example1.swift
protocol P { var pop: String { get } }
extension P {
var pop: String { "slow" }
var pop1: String { pop }
}
protocol Q: P {}
extension Q { var pop: String { "fastQ" } }
protocol R: P {}
View pretty-haskell.md

-- Prompt

Jon Pretty sat down with Edward Kmett to learn about Haskell.

Jon: Edward, tell me about how haskell can make me a better programmer.

-- End Prompt

Edward: Well I'll start off by saying that it's not going to be easy for you. You're not just learning a new programming language, but also a whole new way of thinking and creating software. The problem is, there are very few people who have the knowledge and experience to teach you this stuff. And even if they did, it would take them years to do so. So what we need is an organization like us. We specialize in teaching people to program.

@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]))
}
You can’t perform that action at this time.