diff --git a/prototype/Doubt/Patch.swift b/prototype/Doubt/Patch.swift index fe96595e9..274b79309 100644 --- a/prototype/Doubt/Patch.swift +++ b/prototype/Doubt/Patch.swift @@ -53,6 +53,16 @@ extension Patch { } +// MARK: - Cost calculations + +extension Patch { + /// Returns a function which computes the size of a `patch` as the sum of the sizes of its terms, as computed by `size`. + public static func sum(size: A -> Int)(_ patch: Patch) -> Int { + return (patch.state.before.map(size) ?? 0) + (patch.state.after.map(size) ?? 0) + } +} + + // MARK: - JSON extension Patch {