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
// Playground - noun: a place where people can play | |
import UIKit | |
public class Box<T> { | |
let unbox: T | |
init(_ value: T) { | |
unbox = value | |
} | |
} |
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
extension RLMRealm { | |
public func write(@noescape transaction: ()->()) { | |
self.beginWriteTransaction() | |
transaction() | |
self.commitWriteTransaction() | |
} | |
} | |
public struct Patient { | |
public let info: ModelInfo |
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
// Playground - noun: a place where people can play | |
import UIKit | |
import CoreGraphics | |
public enum Result<T> { | |
case Success(@autoclosure () -> T) | |
case Failure(String) | |
init(_ value: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
func eratosthenes(n: Int) -> [Int]{ | |
return map(enumerate(Array(1...n))) { (index, number) in | |
if number % index == 0 { | |
return -1 | |
} | |
else { | |
return number | |
} | |
} | |
} |
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
struct Scorekeeper { | |
let runningScore: Int | |
let climbingScore: Int | |
let bikingScore: Int | |
let swimmingScore: Int | |
init(runningScore: Int = 0, climbingScore: Int = 0, bikingScore: Int = 0, swimmingScore: Int = 0) { | |
self.runningScore = runningScore | |
self.climbingScore = climbingScore | |
self.bikingScore = bikingScore |
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
// Playground - noun: a place where people can play | |
import Foundation | |
infix operator >>- { associativity left precedence 150 } // Bind | |
infix operator <^> { associativity left } // Functor's fmap (usually <$>) | |
infix operator <*> { associativity left } // Applicative's apply | |
public typealias JSON = AnyObject | |
public typealias JSONObject = Dictionary<String, JSON> |
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 List<T> : Printable { | |
case Empty | |
case Node(@autoclosure() -> T, Box<List<T>>) | |
init(_ head: T, _ tail: Box<List<T>>) { | |
self = .Node(head, tail) | |
} | |
var description: String { | |
get { |
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
infix operator ∘ {} | |
func ∘<A,B,C>(f:B->C, g:A->B) -> (A->C) { | |
return compose(f, g) | |
} | |
func compose<A,B,C>(f:B->C, g:A->B) -> (A->C) { | |
return { x in f(g(x)) } | |
} |
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
reverseInt :: (Integral a) => a -> a | |
reverseInt x = reverseInt' x 0 | |
reverseInt' :: (Integral a) => a -> a -> a | |
reverseInt' n r | |
| n == 0 = r | |
| otherwise = reverseInt' (quot n 10) (10 * r + n `mod` 10) |
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
itoa :: (Integral a) => a -> String | |
itoa x | |
| x == 0 = "0" | |
| x == 1 = "1" | |
| x == 2 = "2" | |
| x == 3 = "3" | |
| x == 4 = "4" | |
| x == 5 = "5" | |
| x == 6 = "6" | |
| x == 7 = "7" |