Created
November 23, 2015 18:29
-
-
Save aamedina/440529b4314f6ddab742 to your computer and use it in GitHub Desktop.
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
| // | |
| // RT.swift | |
| // Clojure | |
| // | |
| // | |
| // | |
| import Foundation | |
| public func typeOf<T> (x: T) -> T.Type { | |
| return T.self | |
| } | |
| public func isa<T> (type: T.Type, _ x: Any?) -> Bool { | |
| return x is T | |
| } | |
| public func null (x: AnyObject?) -> Bool { | |
| return x == nil | |
| } | |
| public func eq<T: AnyObject> (x: T, _ y: T) -> Bool { | |
| return x === y | |
| } | |
| public func equal<T: Equatable> (x: T, _ y: T) -> Bool { | |
| return x == y | |
| } | |
| public func gt<T: Comparable> (x: T, _ y: T) -> Bool { | |
| return x > y | |
| } | |
| public func lt<T: Comparable> (x: T, _ y: T) -> Bool { | |
| return x < y | |
| } | |
| public func gte<T: Comparable> (x: T, _ y: T) -> Bool { | |
| return x >= y | |
| } | |
| public func lte<T: Comparable> (x: T, _ y: T) -> Bool { | |
| return x >= y | |
| } | |
| public func hash<T: Hashable> (x: T?) -> Int { | |
| if x == nil { | |
| return 0 | |
| } else { | |
| return x!.hashValue | |
| } | |
| } | |
| public func hashCombine (seed: Int, hash: Int) -> Int { | |
| return seed ^ hash + 0x9e3779b9 + (seed << 6) + (seed >> 2) | |
| } | |
| public func cast<A, B> (x: A, _ type: B.Type) throws -> B { | |
| return x as! B | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment