Skip to content

Instantly share code, notes, and snippets.

View chriseidhof's full-sized avatar

Chris Eidhof chriseidhof

View GitHub Profile
@chriseidhof
chriseidhof / AppDelegate.swift
Created October 30, 2014 22:54
Image Processing
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
@IBOutlet weak var imageView: NSImageView!
func applicationDidFinishLaunching(aNotification: NSNotification) {
self.imageView.image = convert(myImage())
@chriseidhof
chriseidhof / async.swift
Last active August 29, 2015 14:08
Parallel API
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)
@chriseidhof
chriseidhof / :(
Created November 4, 2014 10:41 — forked from kostiakoval/:(
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
@chriseidhof
chriseidhof / LICENSE
Last active July 16, 2019 13:14
A tiny networking library
Copyright 2015 Chris Eidhof
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHE
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))
}
  • One

    var x = hello
    World
    Test
// This accompanies http://chris.eidhof.nl/posts/repmin-in-swift.html
import UIKit
// Unfortunately, we need Box
public class Box<T> {
public let unbox: T
public init(_ value: T) { self.unbox = value }
}
@chriseidhof
chriseidhof / TypedNotifications.swift
Created January 26, 2015 14:41
Typed Notifications
import Foundation
class Box<T> {
let unbox: T
init(_ value: T) { self.unbox = value }
}
struct Notification<A> {
let name: String
}
//
// main.swift
// MCE
//
// Created by Chris Eidhof on 05/02/15.
// Copyright (c) 2015 Chris Eidhof. All rights reserved.
//
import Foundation