Skip to content

Instantly share code, notes, and snippets.

@archgrove
Created September 16, 2014 15:22
Show Gist options
  • Save archgrove/72b01604a885634aa2af to your computer and use it in GitHub Desktop.
Save archgrove/72b01604a885634aa2af to your computer and use it in GitHub Desktop.
// Playground - noun: a place where people can play
import UIKit
/*
Variables
*/
//
//var x : Int = 1
//x = 2
//
//let y : Int = 1
////y = 2
//
//var z = 1
////z = "test"
/*
Logical operations
*/
//let z = 2;
//if z == 2 {
// println("z was 2")
//} else {
// println("z was not 2")
//}
/*
Loops
*/
//for i in 1...10 {
// println(i)
//}
//
//for (var i = 1; i <= 10; i++)
//{
// println(i)
//}
//
//var i = 0
//while (i++ < 10) {
// i
// println(i)
//}
/*
Functions
*/
//func multiply(lhs : Int, rhs : Int) -> Int {
// return lhs * rhs;
//}
//
//multiply(5, 6)
//
//
//
//
//
//
//func someSideEffect(myParam param : Int) {
// println(param);
//}
//
//someSideEffect(myParam: 5)
//
//multiply(x, 5)
/*
Function types
*/
//
//let aClosure = { (greeting : String, person : String) -> String in
// return "\(greeting), \(person)!"
//}
//
//aClosure("Hello", "Adam")
//aClosure("Hello", "John")
/*
Primitive types
*/
//var anInt : Int = 5
//var aString : String = "Hi there"
//var aFloat : Float = 123.45
//var aDouble : Double = 123.45
//var anArray : [Int] = [1, 2, 3, 4]
//var aDictionary : [Int : String] = [ 1 : "Hello", 2 : "World"]
//var aTuple : (Int, String) = (5, "Foo")
//
//
//
///* Value types */
//var x : [Int] = [1, 2, 3]
//
//var y = x
//x[0] = 3
//x
//y
/*
Object orientation
*/
//
//public class Base {
// private var myState = 1;
//
// public func aMethod() -> Int {
// myState++;
// return myState;
// }
//}
//
//public class Derived : Base {
// public override func aMethod() -> Int {
// myState--;
// return myState;
// }
//}
//
//var anInstance : Base = Derived()
//anInstance.aMethod()
//
//var x : String!
//x.lastPathComponent
/*
Optional chaining
*/
//
//var s : String? = nil
//let r = s?.toInt()?.bigEndian
/*
Enumerate
*/
enum Colour {
case Red;
case Green;
case Blue;
}
let aColour = Colour.Red
switch (aColour) {
case .Red:
println("It's red")
case .Blue:
println("It's blue")
case .Green:
println("It's green")
}
/*
Pattern matching
*/
//
//enum AllColours {
// case GreyScale(intensity : Int)
// case RGB(red : Int, green : Int, blue : Int)
//}
//
//let aNewColour = AllColours.RGB(red: 1, green: 2, blue: 3)
//
//switch (aNewColour) {
//case .GreyScale(let x):
// println(x)
//case .RGB(let r, _, _):
// println(r)
//}
//
//
//let tuple = (1, 2, 3)
//
//let (_, _, v) = tuple
//v
//
//
/*
Parameter evaluation
*/
//
//var someState = 1
//func changeSomeState() -> Bool {
// someState = 2
// return true
//}
//
//if (false && changeSomeState()) {
//}
//
//someState
////
////
////
////
////
//func aComplexFunction(x : Int, y : @autoclosure () -> Bool) -> () {
// if (x == 1)
// {
// println("Not going to need y")
// }
// else
// {
// println("Evaluated y: \(y())")
// }
//}
//
//aComplexFunction(2, changeSomeState())
//
//someState
//
/*
Partial application
*/
//func multiplyBy(lhs : Int)(rhs : Int) -> Int
//{
// return lhs * rhs;
//}
//
//var multiplyBy5 = multiplyBy(5)
//multiplyBy5(rhs: 6)
/*
Extended lambda
*/
//func aTest(x : Int, y : () -> Int)
//{
//
//}
//
//aTest(5) { () -> Int in
// return 5
//}
//func synchronize(lockOn : AnyType, aFunc : () -> AnyType) {
// // lock lockOn
// aFunc()
// // unlock lockOn
//}
//
//
//
//
//
//synchronize (someVar) {
// // Code here
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment