diff --git a/Sources/Units/Units.swift b/Sources/Units/Units.swift index 8fd8909..56c3b74 100644 --- a/Sources/Units/Units.swift +++ b/Sources/Units/Units.swift @@ -412,6 +412,16 @@ public struct UnitValue: return (lhs.value * rhs.value)[lhs.unit] } + public func operation( + value: any ConvertibleToDouble, + op: ( + _ lhs: + any ConvertibleToDouble, _ rhs: any ConvertibleToDouble + ) -> any ConvertibleToDouble + ) -> UnitValue { + op(self.value, value).doubleValue[self.unit] + } + // MARK: - Subscripts for UnitValue /// Allows converting the UnitValue to another Unit using subscript syntax. /// Example: `tenKilos[.pound]`