This file contains 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
// I really like this one | |
func doIt(inout s: D) { | |
if case self = isUniquelyReferenced(&s), | |
self.`self` = true where self { | |
self.`self` = { [unowned x = [self, 7] as Self] n in | |
print(x + n) | |
} as () -> () | |
} | |
} |
This file contains 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
// This one is quite tricky | |
let returnN = getReturnN() | |
func availableToIntCollection<C: CollectionType where C.Generator.Element == Int>(c: C) {} | |
availableToIntCollection([1, 2, 3].lazy.map(returnN)) | |
var a : Int { returnN (n: 3) } |
This file contains 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
// Do you like confusion? I like confusion. Make this compile. Some people may find it easier than others | |
_={${$1($0($2.0))($2.1)[{{({"\($0)"},0)}},{0}]()}}()({$0})(0) |
This file contains 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
// Make this code compile without changing these lines | |
func raw<T: RawRepresentable>(t: T) -> T.RawValue { | |
return t.rawValue | |
} | |
let array : [E] = [.A(true), .B(1), .C("C")] | |
array.map(raw) |
This file contains 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 | |
import XCPlayground | |
XCPSetExecutionShouldContinueIndefinitely() | |
func getAllEmojis(completion: String? -> ()) { | |
let url = NSURL(string: "http://www.unicode.org/Public/UCD/latest/ucd/EmojiSources.txt")! | |
NSURLSession.sharedSession().dataTaskWithURL(url) { data, response, error in | |
guard let data = data where error == nil else { | |
completion(nil) |
This file contains 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
protocol ContextError : ErrorType { | |
mutating func addContext<T>(type: T.Type) | |
} | |
protocol Contextualizable {} | |
extension Contextualizable { | |
func addContext(var error: ContextError) -> ContextError { | |
error.addContext(self.dynamicType) | |
return error | |
} |