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 | |
// https://www.facebook.com/video.php?v=10152735777427200&set=vb.9445547199&type=2&theater | |
var str = "Hello, playground" | |
func getNearbyChars(ch: String) -> Set<String> { | |
switch ch { | |
case "g": return Set(["g","h","f"]) |
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
// | |
// LazyStreamTests.swift | |
// Playground | |
// | |
// Created by kori on 4/20/16. | |
// Copyright © 2016 hiroshi.kori. All rights reserved. | |
// | |
import Foundation |
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
-- Beautiful fibonacci implementation | |
fibs = 0 : 1 : zipWith (+) fibs (tail fibs) |
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
// | |
// TCOTests.swift | |
// Playground | |
// | |
// Created by kori on 4/20/16. | |
// Copyright © 2016 hiroshi.kori. All rights reserved. | |
// | |
import XCTest |
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
protocol MyProtocol: class { | |
typealias MyAlias | |
var something: MyAlias { get } | |
} | |
extension MyProtocol where MyAlias: YourProtocol { | |
func bar() { | |
// !!! Compile Error happens !!! | |
// expected an argument list of type '(Self.AliasTypeAlias)' | |
// self.something.foo { _ in print("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
class Tag { | |
let tagName: NSString | |
let element: NSString | |
init(tagName: NSString, element: NSString) { | |
self.tagName = tagName | |
self.element = element | |
} | |
static let open: NSString = "<" |
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
// 1. same name of functions with different signature in both protocol and protocol extension | |
// 2. someone is conforming to the protocol | |
// This should be compile error though, error does not happen. Instead Compiler crashes in AST -> SIL conversion phase. | |
protocol FooProtocol { | |
func sameName(differentSignature: Bool) -> UITableViewCell? | |
} | |
extension FooProtocol { | |
func sameName() -> UITableViewCell { | |
return UITableViewCell() |
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 | |
// Light-weight utility of observable stream | |
// https://gist.github.com/staltz/868e7e9bc2a7b8c1f754 | |
class Observer<T> { | |
typealias EventHandler = T -> () | |
let eventHandler: EventHandler | |
init(eventHandler: EventHandler) { | |
self.eventHandler = eventHandler | |
} |
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 | |
var str = "Hello, playground" | |
/* | |
class (Eq a, Show a) => Num a where | |
(+) :: a -> a -> a |
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 XCTest | |
//@testable import Playground | |
class StructVsClassTests: XCTestCase { | |
let times = 1000000 | |
// 0.023 sec | |
// 0.002 sec on Release build | |
func testPerformanceStructConstructor() { | |
// This is an example of a performance test case. |