Skip to content

Instantly share code, notes, and snippets.

View oleksii-demedetskyi's full-sized avatar
🎯
Arrow: Language for unidirectional programming

Oleksii Demedetskyi oleksii-demedetskyi

🎯
Arrow: Language for unidirectional programming
View GitHub Profile
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)
}
//: Playground - noun: a place where people can play
import Cocoa
struct AST {
let declarations: [Statement]
}
enum Statement {
case expression(Expression)
//: Playground - noun: a place where people can play
import Cocoa
struct AST {
let declarations: [Statement]
}
enum Statement {
case expression(Expression)
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
}
}
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 -> ()]
//: 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 {
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
}
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
}
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
}
//: Playground - noun: a place where people can play
import Cocoa
var str = "Hello, playground"
struct Test {
var value: Int = 0
mutating func incrementer() -> () -> () {