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 Parsable { | |
static func parse(from object: Any) throws -> Self | |
} | |
public typealias JSON = [String: Any] | |
enum ParseError<T>: Swift.Error { | |
case cannotConvert(value: Any, toType: T.Type) | |
} |
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
//: Playground - noun: a place where people can play | |
import Cocoa | |
struct AST { | |
let declarations: [Statement] | |
} | |
enum Statement { | |
case expression(Expression) |
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
//: Playground - noun: a place where people can play | |
import Cocoa | |
struct AST { | |
let declarations: [Statement] | |
} | |
enum Statement { | |
case expression(Expression) |
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
extension Future { | |
func then<U>(f: T -> Future<U>) -> Future<U> { | |
let promise = Promise<U>() | |
self.onFail { promise.fail() }.onSuccess { | |
f($0).onFail { promise.fail() }.onSuccess { promise.resolve($0) } | |
} | |
return promise.future | |
} | |
} |
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 | |
public struct Future<T> { | |
public let onFail: (() -> ()) -> Future<T> | |
public let onSuccess: (T -> ()) -> Future<T> | |
} | |
public class Promise<T> { | |
private var onFails = [] as [() -> ()] | |
private var onSuccesses = [] as [T -> ()] |
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
//: Playground - noun: a place where people can play | |
import UIKit | |
// credit: http://stackoverflow.com/questions/603907/uiimage-resize-then-crop#605385 | |
/// Cropping is a basic and generic operation on top of UIKit, | |
/// it deserves to be moved to some extension. No need to test it. | |
extension UIImage { | |
func cropToFrame(frame: CGRect) -> UIImage { |
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
struct Counter { | |
var value = 0 | |
enum Event { case Increment, Decrement } | |
mutating func handle(event: Event) { | |
switch event { | |
case .Increment: value += 1 | |
case .Decrement: value -= 1 | |
} |
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
struct Counter { | |
var value = 0 | |
enum Event { case Increment, Decrement } | |
mutating func handle(event: Event) { | |
switch event { | |
case .Increment: value += 1 | |
case .Decrement: value -= 1 | |
} |
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
struct Counter { | |
var value = 0 | |
enum Event { case Increment, Decrement } | |
mutating func handle(event: Event) { | |
switch event { | |
case .Increment: value += 1 | |
case .Decrement: value -= 1 | |
} |
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
//: Playground - noun: a place where people can play | |
import Cocoa | |
var str = "Hello, playground" | |
struct Test { | |
var value: Int = 0 | |
mutating func incrementer() -> () -> () { |