December 2018
Intermediate to advanced
414 pages
10h 19m
English
A recommendation engine can be thought of as a software system that gives you the most relevant answer based on a list of objects:
protocol RecommendationEngine { associatedtype Model var models: [Model] { get } func filter(elements: [Model]) -> [Model] func sort(elements: [Model]) -> [Model]}
We build our recommendation engine around two core methods—one for filtering out the undesired objects and the other around sorting; the most relevant results are always first.
Thanks to protocol extensions, we're able to provide the default implementation for the matching algorithm:
extension RecommendationEngine { func match() -> Model? { // If we only have 0 or 1 models, no need to run the algorithm guard models.count >
Read now
Unlock full access