Skip to content

Instantly share code, notes, and snippets.

enum ComponentId{
case Velocity
case Position
case Size
func describe()->NSString{
return "\(self.hashValue)"
}
}
@mzaks
mzaks / OMDeferred+FailWithResult.m
Created June 18, 2014 12:15
OMDeffered fail with result category
@implementation OMDeferred (FailWithResult)
-(void)fail:(NSError *)error withResult:(id)result{
NSAssert(error, @"Error object should not be nil");
NSAssert(error.domain, @"Error object should have a domain");
if(result){
NSMutableDictionary *newUserInfo = [NSMutableDictionary dictionaryWithDictionary:error.userInfo];
newUserInfo[ERROR_RESULT_KEY] = result;
error = [NSError errorWithDomain:error.domain code:error.code userInfo:newUserInfo.copy];
}
using Entitas;
public class PositionComponent : IComponent {
public int x, y;
public PositionComponent(int x, int y)
{
this.x = x;
this.y = y;
import Foundation
public typealias Action = ()->Void
/**
Bounced action takes interval and action to return another action, which limits the rate at which provided action can be fired.
It is like a bouncer at a discotheque. He will act on your questions only after you shut up for 'interval' of time.
This technique is important if you have action wich should fire on update, however the updates coming in to frequently sometimes.
private protocol List{
var tail : List {get}
}
private struct EmptyList : List{
var tail : List {
return EmptyList()
}
}
enum EnumList<T> {
case Cons(T, EnumList<T>)
case Nil
}
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]
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")
}
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
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")
}