Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (rand[0] == someInt && rand[1] == someInt && . . . && rand[n] == someInt) {
- *do some things*
- }
- extension Sequence {
- func allPass(predicate: (Iterator.Element) -> Bool) -> Bool {
- return first(where: { !predicate($0) }) == nil
- }
- }
- extension SequenceType {
- func allPass(predicate: (Generator.Element) -> Bool) -> Bool {
- for element in self {
- if !predicate(element) { return false }
- }
- return true
- }
- }
- let matches = rand.filter { $0 == someInt }
- if rand.count == matches.count {
- print("there were (matches.count) matches")
- // do some things
- } else {
- print("there were only (matches.count) of (rand.count) total possible matches")
- }
- if rand.reduce(true, combine: {$0 && $1 == someInt})
- {
- print("do some thing")
- }
- // all equal to someInt <=> there is none that is not equal to someInt
- if !(rand.contains { $0 != someInt }) {
- ...
- }
- extension Sequence {
- public func allSatisfy(where predicate: (Self.Iterator.Element) throws -> Bool) rethrows -> Bool {
- return try !self.contains { element throws -> Bool in
- return try !predicate(element)
- }
- }
- }
- if (rand.allSatisfy { $0 == someInt }) {
- ...
- }
Add Comment
Please, Sign In to add comment