Guest User

Untitled

a guest
Jun 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. if (rand[0] == someInt && rand[1] == someInt && . . . && rand[n] == someInt) {
  2.  
  3. *do some things*
  4.  
  5. }
  6.  
  7. extension Sequence {
  8. func allPass(predicate: (Iterator.Element) -> Bool) -> Bool {
  9. return first(where: { !predicate($0) }) == nil
  10. }
  11. }
  12.  
  13. extension SequenceType {
  14. func allPass(predicate: (Generator.Element) -> Bool) -> Bool {
  15. for element in self {
  16. if !predicate(element) { return false }
  17. }
  18. return true
  19. }
  20. }
  21.  
  22. let matches = rand.filter { $0 == someInt }
  23.  
  24. if rand.count == matches.count {
  25. print("there were (matches.count) matches")
  26. // do some things
  27. } else {
  28. print("there were only (matches.count) of (rand.count) total possible matches")
  29. }
  30.  
  31. if rand.reduce(true, combine: {$0 && $1 == someInt})
  32. {
  33. print("do some thing")
  34. }
  35.  
  36. // all equal to someInt <=> there is none that is not equal to someInt
  37. if !(rand.contains { $0 != someInt }) {
  38. ...
  39. }
  40.  
  41. extension Sequence {
  42. public func allSatisfy(where predicate: (Self.Iterator.Element) throws -> Bool) rethrows -> Bool {
  43. return try !self.contains { element throws -> Bool in
  44. return try !predicate(element)
  45. }
  46. }
  47. }
  48.  
  49. if (rand.allSatisfy { $0 == someInt }) {
  50. ...
  51. }
Add Comment
Please, Sign In to add comment