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
enum State { | |
case Success(value:String) | |
case Error(error:NSError) | |
} | |
class Bound:Printable { | |
let pointer:NSErrorPointer | |
var state:State | |
var step:Int = 0 | |
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
class Unwrapper<T, R> { | |
let failed:R? | |
let values:[T] | |
init(values: [T] = [], failed:R? = nil) { | |
self.values = values | |
self.failed = failed | |
} | |
class func unwrap(value:T?, elseReturn safe:R) -> Unwrapper<T, R> { |
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
// This new version seems to be syntactically correct, | |
// but it crashes together with Xcode as of beta 3. | |
// (radar link should appear here) | |
// Find smallest N such that f(N) = nil. | |
func exhaust<T>(fun: Int -> T?) -> Int { | |
var index = 0 | |
while fun(index) { index++ } | |
return index | |
} |
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
// Demonstrates some rather elementary points about code points vs elements | |
import Foundation | |
import Swift | |
extension String { | |
func canonize() -> [Character] { | |
return Array(precomposedStringWithCanonicalMapping) | |
} | |
static func decanonize(chars: [Character]) -> String { |
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
// A different style for an example code by David Owens. | |
// https://github.com/owensd/json-swift/blob/master/src/Error.swift | |
import Foundation | |
/** Creates a new type that is used to represent error information in Swift. | |
This is a new Swift-specific error type used to return error information. | |
The primary usage of this object is to return it as a `Failable` or | |
`FailableOf<T>` from function that could fail. |
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
#!/usr/bin/env xcrun swift -O3 | |
// | |
// utf.swift | |
// | |
// | |
// Created by Ilya Nikokoshev on 8/22/14. | |
// | |
// | |
import Foundation |
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
// ------------------------- | |
// General-purpose functions. Created by Alice. | |
import Foundation | |
func <(lhs:NSDate, rhs:NSDate) -> Bool { | |
// This should be in the standard library. - Alice. | |
return lhs.compare(rhs) == .OrderedAscending | |
} |
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
// For https://gist.github.com/erica/5477d5caccfbff04a802 | |
// MARK: Generic collections | |
import Foundation | |
import Swift | |
infix operator ➜ { associativity left } | |
func ➜(source: [String], f: (String) -> ()) -> () { | |
for element in source { |
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
enum StringPaddingStyle { | |
case Left, Right | |
} | |
func padString(source: String, | |
with character: Character = " ", | |
fill target: Int, | |
style: StringPaddingStyle = .Left | |
) -> String { | |
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
//Filter.swift | |
public mutating func next() -> Base.Element? { | |
var n: Base.Element? | |
for/*ever*/;; { | |
n = _base.next() | |
if n != nil ? _predicate(n!) : true { | |
return n | |
} | |
} |
OlderNewer