Skip to content

Instantly share code, notes, and snippets.

Chris Eidhof chriseidhof

Block or report user

Report or block chriseidhof

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 2019-05-14-protocols-vs-functions.md
title synopsis tags share_image episode book collection author
Swift Tip: Protocols vs. Values
Extensible in different ways
news
/images/blog/2019-05-13-protocols-vs-functions.png
19
advanced-swift
networking
chriseidhof
View networking.swift
import Foundation
struct Resource<A> {
var request: URLRequest
var parse: (Data) throws -> A
}
extension Resource where A: Decodable {
init(get url: URL) {
self.init(request: URLRequest(url: url)) { data in
View graph.swift
import Foundation
/*
Talking points
- It's hard for Node to conform to Codable, because of references
- This is a problem in both directions. For encoding, we need to keep track of what we've already seen. For decoding, we need two-phase initialization.
- But we can convert to sparsegraph, and then we get conformance for free
- to do this, an iterator over all reachable nodes really helps!
View nsnorth.swift
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var rootVC: UINavigationController? = nil
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
View fusion.swift
//
// main.swift
// Deforestation
//
// Created by Chris Eidhof on 29.03.19.
// Copyright © 2019 objc.io. All rights reserved.
//
import Foundation
struct Build<Element, Result> {
View ParseLib.swift
//
// ParseLib.swift
// JsxLib
//
// Created by Chris Eidhof on 19.02.19.
//
import Foundation
public struct ParseError: Error {
View folds.swift
struct Reducer<Element, A> {
let empty: A
let combine: (A, Element) -> A
}
func sum() -> Reducer<Int, Int> {
return Reducer(empty: 0, combine: +)
}
func count<A>() -> Reducer<A, Int> {
View incremental.swift
//
// Incremental.swift
// Bits
//
// Created by Chris Eidhof on 22.11.18.
//
public typealias Token = Int
fileprivate struct Register<A> {
View optionparser.swift
//
// main.swift
// OptionParser
//
// Created by Chris Eidhof on 28.02.19.
// Copyright © 2019 objc.io. All rights reserved.
//
import Foundation
@chriseidhof
chriseidhof / sql.swift
Last active Feb 22, 2019
String Interpolation Experiments
View sql.swift
//
// main.swift
// StringLiterals
//
// Created by Chris Eidhof on 21.02.19.
// Copyright © 2019 objc.io. All rights reserved.
//
import Foundation
You can’t perform that action at this time.