This file contains hidden or 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
extension CollectionType where SubSequence: CollectionType, SubSequence.Index: BidirectionalIndexType, SubSequence.SubSequence == SubSequence { | |
var splits: LazyMapCollection<Range<Self.Index>, (Self.SubSequence, Self.SubSequence)> { | |
return indices.lazy.map { i in | |
(self.prefixUpTo(i), self.suffixFrom(i)) | |
} | |
} | |
var deletes: LazyMapCollection<LazyMapCollection<Range<Self.Index>, (Self.SubSequence, Self.SubSequence)>, [Self.SubSequence.Generator.Element]> { | |
return splits.map { (f,b) in | |
Array(f) + b.dropFirst() | |
} |
This file contains hidden or 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
infix operator /% {associativity right precedence 100 } | |
public struct Rational { | |
private let num, den: IntMax | |
} | |
public func /%(lhs: IntMax, rhs: IntMax) -> Rational { | |
let g = gcd(lhs,rhs) | |
let (n,d) = (lhs / g, rhs / g) | |
if d < 0 { return Rational(num: n * -1, den: d * -1) } |
This file contains hidden or 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
// IntervalTypes | |
public protocol OpenIntervalType { | |
typealias Value | |
func contains(v: Value) -> Bool | |
} | |
public protocol OpenEndedIntervalType: OpenIntervalType { | |
typealias Value: Comparable | |
var val: Value { get } | |
} |
This file contains hidden or 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
SELECT hotel_name | |
FROM hotels | |
WHERE | |
city = 'Waterford' AND | |
hotel_num IN ( | |
SELECT r.hotel_num | |
FROM rooms AS r | |
WHERE r.room_num NOT IN ( | |
SELECT b.room_num | |
FROM bookings AS b |
This file contains hidden or 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
/* | |
Simple hotel-booking database | |
Kieran Herley, Dec 2012 | |
*/ | |
-- Populate hotels table | |
INSERT INTO hotels VALUES | |
(1,"Hotel Splendide","Cork"); | |
INSERT INTO hotels VALUES | |
(2,"Seaview Hotel","Galway"); |
This file contains hidden or 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
func ==<H: Hashable, E: Equatable>(lhs: [H:E]?, rhs: [H:E]?) -> Bool { | |
switch (lhs,rhs) { | |
case let (a?,b?): return a == b | |
case (nil,nil): return true | |
default: return false | |
} | |
} |
This file contains hidden or 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 TransformElement<T> { case Skip, Stop, Continue(T) } | |
extension TransformElement { | |
func map<U>(@noescape f: T -> U) -> TransformElement<U> { | |
switch self { | |
case .Skip: return .Skip | |
case .Stop: return .Stop | |
case let .Continue(x): return .Continue(f(x)) | |
} | |
} |
This file contains hidden or 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 Node { | |
let name: String | |
init(_ name: String) { | |
self.name = name | |
} | |
} | |
extension RangeReplaceableCollectionType where Generator.Element == Node { | |
mutating func node(name: String) -> Node { | |
if let firstMatch = self.lazy.filter({ n in n.name == name }).first { |
This file contains hidden or 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
if !myCondition, let myValue = getExpensiveComputationResult() { | |
} else { | |
} |
This file contains hidden or 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
public struct OrderedDictionary<Tk: Hashable, Tv> : MutableCollectionType { | |
var keys: [Tk] = [] | |
var values: [Tk:Tv] = [:] | |
public typealias Index = Int | |
public var count: Int { | |
return self.keys.count | |
} | |