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 | |
| /** | |
| Creates and returns a new debounced version of the passed block which will postpone its execution until after wait seconds have elapsed since the last time it was invoked. | |
| It is like a bouncer at a discotheque. He will act only after you shut up for some time. | |
| This technique is important if you have action wich should fire on update, however the updates are to frequent. | |
| Inspired by debounce function from underscore.js ( http://underscorejs.org/#debounce ) | |
| */ | |
| public func dispatch_debounce_block(wait : NSTimeInterval, queue : dispatch_queue_t = dispatch_get_main_queue(), block : dispatch_block_t) -> dispatch_block_t { |
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
| private protocol List{ | |
| var tail : List {get} | |
| } | |
| private struct EmptyList : List{ | |
| var tail : List { | |
| return EmptyList() | |
| } | |
| } |
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
| enum EnumList<T> { | |
| case Cons(T, EnumList<T>) | |
| case Nil | |
| } |
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
| let list = 1 => 2 => 3 => nil | |
| println("\(list.value)") //1 | |
| for value in list { | |
| println(value) // 1 2 3 | |
| } | |
| let l1 = list[0] | |
| let l2 = list[5] | |
| let l3 = list[2] |
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 measureArray(){ | |
| let time = NSDate() | |
| var a = [0] | |
| for i in 1...1_000{ | |
| a.append(i) | |
| } | |
| let after = NSDate() | |
| println("\(after.timeIntervalSince1970 - time.timeIntervalSince1970) Array 1K") | |
| } |
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 Box<T>{ | |
| let value : T | |
| init(_ value : T ){ | |
| self.value = value | |
| } | |
| } | |
| enum EList<T> { | |
| case Cons(Box<T>, Box<EList>) // Box the value T to work around a runtime deadlock bug in Swift | |
| case Nil |
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 measureList(){ | |
| let time = NSDate() | |
| var a = 0 => nil | |
| for i in 1...1_000{ | |
| a = i => a | |
| } | |
| let after = NSDate() | |
| println("\(after.timeIntervalSince1970 - time.timeIntervalSince1970) List 1K") | |
| } |
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
| typealias TPerson = (name:String, age:Int, male:Bool) | |
| struct SPerson{ | |
| let name : String | |
| let age : Int | |
| let male : Bool | |
| } | |
| enum EPerson { | |
| case Male(name: String, age : 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
| func measureTuple(){ | |
| var name : String = "" | |
| let time = NSDate() | |
| for i in 1...10_000_000{ | |
| let p = TPerson("some", 25, true) | |
| name = p.name | |
| } | |
| let after = NSDate() | |
| println("\(after.timeIntervalSince1970 - time.timeIntervalSince1970) Tuple 10M") | |
| println(name) |
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
| context main | |
| component Position { | |
| x : Int, | |
| y : Int | |
| } | |
| component Velocity { | |
| x : Int, | |
| y : Int |