Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Eidhof chriseidhof

View GitHub Profile
View asb.md
@chriseidhof
chriseidhof / type-constraints.swift
Last active Aug 29, 2015
Swift Constraints on extension?
View type-constraints.swift
enum Sum<L,R> {
case Left(@auto_closure () -> L)
case Right(@auto_closure () -> R)
}
protocol GShow {
func gshow() -> String
}
extension String : GShow {
View enum.swift
enum PageType {
case Markdown
case HTML
case XML
}
extension PageType : DebugPrintable {
var debugDescription : String {
switch self {
case .Markdown: return "Markdown"
@chriseidhof
chriseidhof / Result.m
Created Sep 11, 2014
nilResultAfterTimeOut
View Result.m
id nilResultAfterTimeOut(int64_t timeoutInNanoSeconds, ResultBlock block) {
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
dispatch_time_t timeoutTime = dispatch_time(DISPATCH_TIME_NOW, timeoutInNanoSeconds);
__block id result = nil;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
result = block();
dispatch_semaphore_signal(semaphore);
});
View async.swift
enum Either<A,B> {
case Left(A)
case Right(B)
}
// Not sure about which cases this should have...
enum Async<A> {
case Delayed(() -> Async<A>)
case Result(A)
case Failure(NSError)
View :(
import Foundation
import ImageIO
infix operator >>= { associativity left }
func >>=<A,B>(l: A?, r: A -> B?) -> B? {
if let x = l {
return r(x)
}
return nil
View transducer-type.swift
import Foundation
// A bunch of convenience things
func const <A, B> (b: B) -> A -> B {
return { _ in b }
}
func repeat <A> (n: Int) -> A -> [A] {
return { a in
return map(Array(1...n), const(a))
}
View test.md
  • One

    var x = hello
    World
    Test
View mce.swift
//
// main.swift
// MCE
//
// Created by Chris Eidhof on 05/02/15.
// Copyright (c) 2015 Chris Eidhof. All rights reserved.
//
import Foundation
You can’t perform that action at this time.