Summable is a Swift protocol for types whose instances can be combined with the + operator. It lets weighted graph types accept generic weights while requiring addition; weights must also be Comparable for graph algorithms that select the smallest edge. section 4.3
public protocol Summable {
static func +(lhs: Self, rhs: Self) -> Self
}
The protocol declares one requirement: a static + operator that combines two values of the same type. section 4.3
Using numeric weights
Swift’s numeric types already implement +, so they can receive Summable conformance through extensions such as extension Int: Summable {}. A generic WeightedGraph<String, Int> can then store city-to-city distances and add edge weights when computing a total. section 4.3
