[swift-evolution] [pitch] adding toggle to Bool

Ben Cohen ben_cohen at apple.com
Fri Jan 12 11:17:12 CST 2018


+1 for toggle, seems the clear winner for me.

> On Jan 12, 2018, at 8:29 AM, Cheyo Jimenez via swift-evolution <swift-evolution at swift.org> wrote:
> 
> It’s a slippery slope because it makes me want to have something like `not()` added to the library. I don’t think it’s worth it. 
> 

I would love to have not(), but for a different purpose:

func not<T>(_ predicate: @escaping (T)->Bool) -> (T)->Bool {
  return { !predicate($0) }
}

let noScrubs = guys.filter(not(isBusta))

I guess you could overload a version of ! for predicates but that doesn’t seem wise.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20180112/57d60a0f/attachment.html>


More information about the swift-evolution mailing list