Oh I totally misunderstood it.
isOn
should be true
if there's an odd
number of true
s, right? (Conversely, true if there is not an even number of true
s)
Couldn't that be expressed as just a counting operation?
isOn = !switches
.lazy
.filter(\.self)
.count
.isMultiple(of: 2)
This is where a count(where:)
would come in really useful, to remove the need for .lazy.filter()
. An isOdd
and isEven
function would be cool too. If you add extensions for those, you get this down to:
isOn = switches.count(where: \.self).isOdd