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
| var randomNumbers = [42, 12, 88, 62, 63, 56, 1, 77, 88, 97, 97, 20, 45, 91, 62, 2, 15, 31, 59, 5] | |
| func partition(v: Int[], left: Int, right: Int) -> Int { | |
| var i = left | |
| for j in (left + 1)..(right + 1) { | |
| if v[j] < v[left] { | |
| i += 1 | |
| (v[i], v[j]) = (v[j], v[i]) | |
| } | |
| } |
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 UIKit | |
| class Thing { | |
| var value : Int | |
| init(v: Int) { | |
| value = v | |
| } | |
| } | |
| class ThingBST { |
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 Prelude | |
| public struct Lens<A, B> { | |
| private let get: A -> B | |
| private let set: (A, B) -> A | |
| public init(get: A -> B, set: (A, B) -> A) { | |
| self.get = get | |
| self.set = set | |
| } |
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 Graph: | |
| def __init__(self): | |
| self.nodes = set() | |
| self.edges = defaultdict(list) | |
| self.distances = {} | |
| return self | |
| def add_node(self, value): | |
| self.nodes.add(value) | |
| return self |
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 PhoneCall { | |
| var identifier: Int { get } | |
| var isNil: Bool { get } | |
| func hangUp() | |
| } | |
| class RealPhoneCall: PhoneCall { | |
| let identifier: Int | |
| let isNil = false |
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
| let numbers = AnySequence { () -> AnyGenerator<Int> in | |
| var i = 1 | |
| return anyGenerator { | |
| return i++ | |
| } | |
| }.lazy | |
| let fizzes = numbers.map { $0 % 3 == 0 ? "Fizz" : "" } | |
| let buzzes = numbers.map { $0 % 5 == 0 ? "Buzz" : "" } |
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<Element> { | |
| case Nil | |
| indirect case Cons(head: Element, tail: List<Element>) | |
| } | |
| struct ListGenerator<Element> : GeneratorType { | |
| private var list: List<Element> | |
| mutating func next() -> Element? { | |
| switch list { | |
| case .Nil: return nil |
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 Cocoa | |
| enum CoroutineState { | |
| case Fresh, Running, Blocked, Canceled, Done | |
| } | |
| struct CoroutineCancellation: ErrorType {} | |
| class CoroutineImpl<InputType, YieldType> { | |
| let body: (yield: YieldType throws -> InputType) throws -> Void |
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
| // | |
| // CollectionViewDataSource.swift | |
| // Khan Academy | |
| // | |
| // Created by Andy Matuschak on 10/14/14. | |
| // Copyright (c) 2014 Khan Academy. All rights reserved. | |
| // | |
| import UIKit |
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 User { | |
| let id: Int | |
| let name: String | |
| let email: String? | |
| } | |
| extension User: JSONDecodable { | |
| static func create(id: Int, name: String, email: String?) -> User { | |
| return User(id: id, name: name, email: email) | |
| } |