Get it from the App Store.
In XCode's Preferences > Downloads you can install command line tools.
| protocol Num { | |
| class func zero() -> Self | |
| func succ() -> Self | |
| func add(y: Self) -> Self | |
| func multiply(y: Self) -> Self | |
| } | |
| extension Int32: Num { | |
| static func zero() -> Int32 { return 0 } | |
| func succ() -> Int32 { return self + 1 } |
| // F#'s "pipe-forward" |> operator | |
| // | |
| // Also "Optional-chaining" operators |>! and |>& | |
| // | |
| // And adapters for standard library map/filter/sorted | |
| infix operator |> { precedence 50 associativity left } | |
| infix operator |>! { precedence 50 associativity left } | |
| infix operator |>& { precedence 50 associativity left } | |
| infix operator |>* { precedence 50 associativity left } |
Moved to repository: https://github.com/Mailcloud/swift-serializer
| // This code accompanies a blog post: http://chris.eidhof.nl/posts/json-parsing-in-swift.html | |
| // | |
| // As of Beta5, the >>= operator is already defined, so I changed it to >>>= | |
| import Foundation | |
| let parsedJSON : [String:AnyObject] = [ | |
| "stat": "ok", | |
| "blogs": [ |
| // Playground - noun: a place where people can play | |
| // I wouldn't want a pair of birds that were... too demonstrative. | |
| func idiot<A>(a : A) -> A { | |
| return a | |
| } | |
| func kestrel<A, B>(a : A) -> B -> A { | |
| return { _ in a } |
| // Creating a generic recursive data structure with autoclosure. (READ ALL NOTES; THIS MAY NOT DO WHAT YOU WANT.) | |
| // Closures are reference types, so the size is known (? I think ?) | |
| // Note that this is just because of unimplemented features in the compiler in Beta5 | |
| // There's no reason to think this is a long-term requirement. | |
| // IMPORTANT: the closure will run every time you access this value, so if that has | |
| // side effects, this won't work. It's only possible on pure value types. | |
| // But the fact that this works as expected is actually kind of incredible. | |
| // Think about what is required for it to work out the type for NestedList.Elem("first"). |
| import Foundation | |
| // Executes an array of blocks in parallel, but only returns after they're all done. | |
| func parallel(blocks: [() -> ()]) { | |
| let group = dispatch_group_create() | |
| let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) | |
| for block in blocks { | |
| dispatch_group_async(group, queue, block) | |
| } |
| // | |
| // main.swift | |
| // pggrep - updated 12/4/15 | |
| // Created by Erica Sadun on 6/17/15. | |
| // Copyright © 2015 Erica Sadun. All rights reserved. | |
| // | |
| import Foundation | |
| extension String { |
| //: Playground - noun: a place where people can play | |
| //: http://webyrd.net/scheme-2013/papers/HemannMuKanren2013.pdf | |
| typealias Var = Int | |
| typealias Subst = [(Var, Term)] | |
| typealias State = (Subst, Int) | |
| typealias Goal = State -> Stream | |
| indirect enum Stream { | |
| case Nil, Cons(State, Stream), Lazy(() -> Stream) |