Instead of
assert(!array.isEmpty, "Array guaranteed to be non-empty because...")
let lastItem = array.last!
guard !array.isEmpty
else { fatalError("Array guaranteed to be non-empty because...") }
// ... etc ...
Instead of
assert(!array.isEmpty, "Array guaranteed to be non-empty because...")
let lastItem = array.last!
guard !array.isEmpty
else { fatalError("Array guaranteed to be non-empty because...") }
// ... etc ...
// TODO: insert guards to use open-source version of random() if necessary | |
func random(x: Int) -> Int { | |
return Int(arc4random_uniform(UInt32(endBoundary))) | |
} | |
extension CollectionType { | |
/// create a lazy succession of randomly ordered indices | |
/// |
//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 | |
} | |
} |
enum StringPaddingStyle { | |
case Left, Right | |
} | |
func padString(source: String, | |
with character: Character = " ", | |
fill target: Int, | |
style: StringPaddingStyle = .Left | |
) -> String { | |