assargadon / Protego
About Protego
Pleasant way to deal with nil's in business calculations. It provides "protected" versions of common methods/operators, which deals with nil's in clear and intuitive way.
Imagine, you have amount, price, and you want to calculate
total := amount * price. But what if amount or price are nil's?
You can add nil checks, of course, but with Protego you have "protected version" of multiplication: total := amount *@ price. If both operators are not nil, then it works like normal multiplication. If any of operators (or both) are nil, it returns nil.
If you want to calculate grand total over your invoice, you may do something as grandTotal := collectionOfTotals sum. But if any element of the collectionOfTotals are nil, the calculation will fail with exception. Same for the empty collection.
With Protego you just use grandTotal := collectionOfTotals sum_protected. It will calculate the sum of not-nil elements. And it will return nil for empty collection.
And so on, there are many protected operators. See Protego-Tests for full list.
