Skip to content

Instantly share code, notes, and snippets.

@owensd owensd/mem.swift Secret
Created Aug 22, 2014

Embed
What would you like to do?
//
// 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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.