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
struct ModelIterator: IteratorProtocol { | |
private let database: Database | |
private var index = 0 | |
init(database: Database = .shared) { | |
self.database = database | |
} | |
mutating func next() -> Model? { | |
let model = database.model(at: 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
func searchForModel(matching query: String) -> Model? { | |
for model in ModelSequence() { | |
if model.title.contains(query) { | |
return model | |
} | |
} | |
return nil | |
} |
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 ModelLoader { | |
func loadAllModels() -> AnySequence<Model> { | |
return AnySequence { () -> AnyIterator<Model> in | |
var index = 0 | |
return AnyIterator { | |
let model = database.model(at: index) | |
index += 1 | |
return model | |
} |
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
echo "$(date +%s)" > "buildtimes.log" |
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
startime=$(<buildtimes.log) | |
endtime=$(date +%s) | |
deltatime=$((endtime-startime)) | |
newline=$'\n' | |
echo "[Start] $startime$newline[End] $endtime$newline[Delta] $deltatime" > "buildtimes.log" |
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
func +<A: IntegerConvertible, B: IntegerConvertible>(lhs: A, rhs: B) -> CustomNumber { | |
return CustomNumber(int: lhs.int + rhs.int) | |
} |
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
func addNumbers() -> CustomNumber { | |
return CustomNumber(int: 1) + | |
CustomNumber(int: 2) + | |
CustomNumber(int: 3) + | |
CustomNumber(int: 4) + | |
CustomNumber(int: 5) | |
} |
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
extension IntegerConvertible { | |
func add<T: IntegerConvertible>(_ number: T) -> CustomNumber { | |
return CustomNumber(int: int + number.int) | |
} | |
} | |
func addNumbers() -> CustomNumber { | |
return CustomNumber(int: 1).add(CustomNumber(int: 2)) | |
.add(CustomNumber(int: 3)) | |
.add(CustomNumber(int: 4)) |
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
extension User { | |
func toJSON() -> [String : Any] | |
return [ | |
"firstName": firstName, | |
"lastName": lastName, | |
"age": age, | |
"friends": friends.map { $0.toJSON() }, | |
"coworkers": coworkers.map { $0.toJSON() }, | |
"favorites": favorites.map { $0.toJSON() }, | |
"messages": messages.map { $0.toJSON() }, |
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
extension User { | |
func toJSON() -> [String : Any] { | |
var json = [String : Any]() | |
json["firstName"] = firstName | |
json["lastName"] = lastName | |
json["age"] = age | |
json["friends"] = friends.map { $0.toJSON() } | |
json["coworkers"] = coworkers.map { $0.toJSON() } | |
json["favorites"] = favorites.map { $0.toJSON() } | |
json["messages"] = messages.map { $0.toJSON() } |