Skip to content

Instantly share code, notes, and snippets.

@DonaldHays
DonaldHays / Promise.swift
Created June 9, 2014 00:56
A basic Promise implementation in Swift that takes a worker and supports "then" and "done" methods. The worker runs on a background queue. The callbacks to "then" and "done" run on the main queue. I give no guarantees that this is actually production-quality :D
//
// Promise.swift
//
// Created by Donald Hays on 6/4/14.
//
import Foundation
/**
* A Promise is a container of a single value. That value will be assigned only
import Foundation
/// Represents a person for the purposes of Secret Santa pairing.
struct Person: Equatable, CustomStringConvertible {
/// The person's given name.
var givenName: String
/// The person's family name.
var familyName: String
@DonaldHays
DonaldHays / Date.swift
Created November 3, 2015 08:08
A Date type built in pure Swift
import Swift
/// A `TimeInterval` represents a length of time in seconds.
public typealias TimeInterval = Double
/// A `Date` represents a single point in time.
public struct Date: Hashable, Comparable, CustomStringConvertible {
// MARK: -
// MARK: Public Properties
@DonaldHays
DonaldHays / UUID.swift
Created November 3, 2015 08:09
A UUID type built in pure Swift
import Swift
/// `UUID` represents a 128-bit value suitable for uniquely identifying things.
public struct UUID: Hashable {
// MARK: -
// MARK: Public Properties
/// The raw bytes of the UUID.
public let data: Data
@DonaldHays
DonaldHays / Path.swift
Created February 22, 2016 18:28
An implementation of a Path type in Swift
//
// Path.swift
//
// Created by Donald Hays on 9/17/15.
//
import Darwin
/// `Path` represents the basic components of a file system path.
public struct Path: Hashable, CustomStringConvertible, StringLiteralConvertible, ArrayLiteralConvertible {