Skip to content

Instantly share code, notes, and snippets.

@mbrandonw
mbrandonw / transducer-type.swift
Last active October 18, 2020 16:56
How to get a transducer type without higher kinds
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))
}
@alloy
alloy / README.markdown
Created August 8, 2014 09:56
Learn the LLVM C++ API by example.

The easiest way to start using the LLVM C++ API by example is to have LLVM generate the API usage for a given code sample. In this example it will emit the code required to rebuild the test.c sample by using LLVM:

$ clang -c -emit-llvm test.c -o test.ll
$ llc -march=cpp test.ll -o test.cpp
@marcprux
marcprux / XCTAssertEqualOptional.swift
Created July 23, 2014 17:48
XCTAssertEqual that handles optional unwrapping
/// like XCTAssertEqual, but handles optional unwrapping
public func XCTAssertEqualOptional<T: Any where T: Equatable>(expression1: @auto_closure () -> T?, expression2: @auto_closure () -> T?, _ message: String? = nil, file: String = __FILE__, line: UInt = __LINE__) {
if let exp1 = expression1() {
if let exp2 = expression2() {
XCTAssertEqual(exp1, exp2, message ? message! : "", file: file, line: line)
} else {
XCTFail(message ? message! : "exp1 != nil, exp2 == nil", file: file, line: line)
}
} else if let exp2 = expression2() {
XCTFail(message ? message! : "exp1 == nil, exp2 != nil", file: file, line: line)
@subdigital
subdigital / xc
Created April 19, 2013 14:27
Open the first Xcode workspace or project found
xcode_proj=`find . -name "*.xc*" -d 1 | sort -r | head -1`
if [ `echo -n $xcode_proj | wc -m` == 0 ]
then
echo "No xcworkspace/xcodeproj file found in the current directory."
exit 1
fi
echo "Found $xcode_proj"
open $xcode_proj