TechNewsHeaven {{source.name}}




Seemingly Impossible Swift Programs
2018-12-10T07:08:05.7581062Z - Brandon Williams / Hacker News
For example, Bool :extension Bool { static func allSatisfy ( _ p : ( Bool ) -> Bool ) -> Bool { return p ( true ) && p ( false ) } } Bool . I’m going to overload + for this purpose:func + ( lhs : Bit , rhs : BitSequence ) -> BitSequence { return BitSequence { $0 == 0 ? Let’s give that a shot in code:extension BitSequence { static func find ( _ p : ( BitSequence ) -> Bool ) -> BitSequence { if BitSequence . zero + s ) }) { // We found a sequence `s` such that `.zero + s` satisfies // the predicate. So, we can lazily defer that by making the right side of + an autoclosure :func + ( lhs : Bit , rhs : @escaping @autoclosure () -> BitSequence ) -> BitSequence { return BitSequence { $0 == 0 ?

Your favorite news


Popular news




Recommended news