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 | |
| extension NSURL : StringLiteralConvertible { | |
| class func convertFromStringLiteral(value: String) -> Self { | |
| return self(string: value) | |
| } | |
| class func convertFromExtendedGraphemeClusterLiteral(value: String) -> Self { | |
| return self(string: 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
| import Foundation | |
| struct Meter { | |
| var value: Double | |
| init(_ value: Double) { | |
| self.value = value | |
| } | |
| var mm: Double { return value * 1000.0 } |
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 < { associativity left } | |
| func <<T : Comparable>(lhs: T, rhs: T) -> ((T, T) -> Bool, () -> T) -> Bool { | |
| return { (op: (T, T) -> Bool, value: () -> T) in | |
| (lhs < rhs) && op(rhs, value()) | |
| } | |
| } | |
| func <<T: Comparable>(lhs: ((T, T) -> Bool, () -> T) -> Bool, rhs: @autoclosure () -> T) -> Bool { | |
| return lhs({$0 < $1}, rhs) |
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 < { associativity left } | |
| // left-most comparison | |
| func <<T : Comparable>(lhs: T, rhs: T) -> ((T, T) -> Bool, () -> T) -> Bool { | |
| return { (op: (T, T) -> Bool, value: () -> T) in | |
| (lhs < rhs) && op(rhs, value()) | |
| } | |
| } | |
| // mid comparisons |
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 encode<T>(var value: T) -> NSData { | |
| return withUnsafePointer(&value) { p in | |
| NSData(bytes: p, length: sizeofValue(value)) | |
| } | |
| } | |
| func decode<T>(data: NSData) -> T { | |
| let pointer = UnsafeMutablePointer<T>.alloc(sizeof(T.Type)) | |
| data.getBytes(pointer) | |
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 TakeSequenceView<Base : SequenceType> : SequenceType { | |
| let base: Base | |
| let n: Int | |
| init(_ base: Base, n: Int) { | |
| self.base = base | |
| self.n = n | |
| } | |
| func generate() -> GeneratorOf<Base.Generator.Element> { |
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
| // Interpol.playground | |
| import CoreGraphics | |
| typealias Time = CFTimeInterval | |
| typealias Value = CGFloat | |
| typealias Point = CGPoint | |
| typealias Vector = CGVector | |
| typealias Size = CGSize | |
| typealias Rect = CGRect |
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 ??= { | |
| associativity right | |
| precedence 90 | |
| assignment | |
| } | |
| func ??=<T>(inout optional: T?, defaultValue: @autoclosure () -> T?) -> T? { | |
| optional = optional ?? defaultValue() |
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 ViewModel | |
| class Attribute | |
| attr_reader :name | |
| attr_accessor :model_value, :view_value | |
| def initialize(name, model_value = :_undefined, view_value = :_undefined) | |
| @name = name | |
| @model_value = model_value | |
| @view_value = view_value | |
| end |
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
| final class Box<T> { | |
| let value: T | |
| init(_ value: T) { | |
| self.value = value | |
| } | |
| } | |
| protocol DataType : Printable { |