This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* We've defined "traits" by which we can type an integer that are characteristic of its value. | |
* These traits can even be subtraits of other traits (like both positive and negative being nonzero). | |
* | |
* We can use these traits in the type signatures of functions to indicate what trait will be returned | |
* as a function of the passed-in traits. | |
* | |
* Even cooler, we can specify properties of the traits such that we can runtime-verify the correctness | |
* of these labels (in case a function was improperly annotated, for example). | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class Nat<F> : FunctorOf<F> { | |
let pred : Optional<F> | |
override init() { | |
self.pred = nil | |
} | |
init(pred : F) { | |
self.pred = pred | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NSScanner+Swift.swift | |
// A set of Swift-idiomatic methods for NSScanner | |
// | |
// (c) 2015 Nate Cook, licensed under the MIT license | |
import Foundation | |
extension NSScanner { | |
// MARK: Strings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Lens<T, A> { | |
let get: T -> A | |
let mod: (T, A -> A) -> T | |
func set(t: T, _ a: A) -> T { | |
return self.mod(t) { _ in a } | |
} | |
} | |
infix operator >>> {} | |
func >>><S, T, A>(l: Lens<S, T>, r: Lens<T, A>) -> Lens<S, A> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# A shell script to provide a meaningful diff output for a merge commit that can be used to determine whether the merge was evil. | |
# The script should be run from outside the git repository, with two arguments: | |
# 1 - the directory of the git repository | |
# 2 - the SHA for the merge commit to inspect | |
# The script will output one file: | |
# - the merge redone fresh without any conflicts resolved, diff'ed to the actual merge | |
output_file="diff.txt" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func executeFetchRequestT<T:AnyObject>(request:NSFetchRequest, managedObjectContext:NSManagedObjectContext, error: NSErrorPointer = nil) -> [T]? { | |
var localError: NSError? = nil | |
if let results:[AnyObject] = managedObjectContext.executeFetchRequest(request, error: &localError) { | |
if results.count > 0 { | |
if results[0] is T { | |
let asT:[T] = results as [T] | |
return .Some(asT) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// comparing speed of generic function vs. Slice -> Array conversion | |
import Foundation | |
// sum function that takes a Slice<Int> | |
func sumSlice(numbers: Slice<Int>) -> Int { | |
return numbers.reduce(0, +) | |
} | |
// sum function that takes an Array<Int> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Original by Erica Sadun | |
// Source: http://ericasadun.com/2014/06/24/swift-reflection-dump/ | |
import UIKit | |
import Foundation | |
func typestring(x : Any) -> String | |
{ | |
if let obj = x as? NSObject { | |
return NSStringFromClass((x as NSObject).dynamicType) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Regex { | |
let pattern: String | |
let options: NSRegularExpressionOptions! | |
private var matcher: NSRegularExpression { | |
return NSRegularExpression(pattern: self.pattern, options: nil, error: nil) | |
} | |
required init(pattern: String, options: NSRegularExpressionOptions = nil) { | |
self.pattern = pattern |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension String | |
{ | |
var length: Int { | |
get { | |
return countElements(self) | |
} | |
} | |