Skip to content

Instantly share code, notes, and snippets.

@owensd

owensd/mem.swift Secret

Created August 22, 2014 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owensd/a7739c13dc8de83da0f4 to your computer and use it in GitHub Desktop.
Save owensd/a7739c13dc8de83da0f4 to your computer and use it in GitHub Desktop.
//
// main.swift
// MemoryInvestigation
//
// Created by David Owens II on 8/22/14.
// Copyright (c) 2014 Kiad Software. All rights reserved.
//
import Foundation
typealias IntErrorTupleType = (Int?, Error?)
func IntErrorTuple(value: Int) -> IntErrorTupleType {
return (value, nil)
}
func left<T, U>(tuple: (T, U)) -> T {
return tuple.0
}
func right<T, U>(tuple: (T, U)) -> U {
return tuple.1
}
func IntErrorTuple(error: Error) -> IntErrorTupleType {
return (nil, error)
}
func either<T>(value: T) -> Either<T, Error> {
return Either(left: value)
}
func failable<T>(value: T) -> FailableOf<T> {
return FailableOf(value)
}
func tuple<T>(value: T) -> (T?, Error?) {
return (value, nil)
}
func typedTuple(value: Int) -> IntErrorTupleType {
return IntErrorTuple(value)
}
//// test: either
//for var i = 0; i < 100_001; i++ {
// let r = either(i)
// if (r.right != nil) {
// println("error at \(i)")
// }
//}
//// test: failable
//for var i = 0; i < 100_001; i++ {
// let r = failable(i)
// if (r.error != nil) {
// println("error at \(i)")
// }
//}
//// test: tuple
//for var i = 0; i < 100_001; i++ {
// let r = tuple(i)
// if (r.1 != nil) {
// println("error at \(i)")
// }
//}
// test: tuple
for var i = 0; i < 100_001; i++ {
let r = typedTuple(i)
if (right(r) != nil) {
println("error at \(i)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment