Skip to content

Instantly share code, notes, and snippets.


Gordon Fontenot gfontenot

Block or report user

Report or block gfontenot

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
gfontenot / ElmSpike.swift
Created Aug 3, 2018
Quick spike on an elm-ish architecture in Swift
View ElmSpike.swift
// Dumb value types representing UIViews. Comperable to our current models like Button.Model
struct StackView<Message> {
let children: [View<Message>]
struct Label {
let text: String
View CaseEnumeration.swift
func assert(_ cond: @autoclosure () -> Bool) -> String {
if cond() {
return ""
} else {
return ""
#if !swift(>=4.2)
protocol KnownEnum: RawRepresentable, Hashable where RawValue == String {
View goroutines.swift
import Foundation
enum Message<T> {
case value(T)
case finished
protocol Channel: IteratorProtocol {
func send(_ value: Message<Element>)
gfontenot / Decoding.swift
Created Jul 22, 2015
Example of using partial application as a way to solve side loaded JSON with immutable value objects
View Decoding.swift
// Returning a function here, instead of a fully realized object
extension Company: Decodable {
static func decode(j: JSON) -> Decoded<[People] -> Company> {
return create
<^> j <| "id"
<*> j <| ["attributes", "name"]
View properties.swift
// stored property, no default value
let foo: String
// stored property, default value
let foo: String = "foo"
// or
let foo = "foo"
// computed property, no custom setter
var foo: String {
View functionalRefactor.swift
// Original implementation with multiple returns:
class func fromId(id: String) -> Office? {
let officesData = JSONData.load("offices") as? [[String: String]] ?? []
let officeData = officesData.filter { $0["id"] == id }.first
if let office = officeData {
return decode(JSONValue.parse(office))
gfontenot / decodeDict.swift
Created Feb 19, 2015
example of decoding dictionary objects with Argo/FP
View decodeDict.swift
import Argo
import Runes
func +<T, V>(lhs: [T: V], rhs: [T: V]) -> [T: V] {
var dict = lhs
for (key, val) in rhs {
dict[key] = val
return dict
View requests.swift
import Foundation
infix operator >>- { associativity left precedence 150 }
public func >>-<T, U>(a: T?, f: T -> U?) -> U? {
return a.flatMap(f)
extension Optional {
func flatMap<U>(f: T -> U?) -> U? {
switch self {
View DispatchgGroup.swift
import Foundation
class DispatchGroup {
private var blocks: [dispatch_block_t] = []
private let dispatch_queue = dispatch_queue_create("", DISPATCH_QUEUE_CONCURRENT)
private let dispatch_group = dispatch_group_create()
func andThen(block: dispatch_block_t) -> Group {
blocks += [block]
return self
View gist:9789230
### Keybase proof
I hereby claim:
* I am gfontenot on github.
* I am gfontenot ( on keybase.
* I have a public key whose fingerprint is FC96 877D E91A C0B4 381D D33A 0BF4 A6C7 2DA8 F9CE
To claim this, I am signing this object:
You can’t perform that action at this time.