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 | |
/// |
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 ...
def fold(s, p = 0): | |
for i in [i+1 for (i, c), n in zip(enumerate(s), s[1:]+' ') if c != n]: p = print(s[p], i-p, sep="", end="") or i |