Advertisement
Guest User

Untitled

a guest
Aug 1st, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. postfix operator < {}
  2. postfix operator <= {}
  3. prefix operator > {}
  4. prefix operator >= {}
  5. postfix func < <C : Comparable>(lhs: C)(_ rhs: C) -> Bool {
  6. return lhs < rhs
  7. }
  8. postfix func <= <C : Comparable>(lhs: C)(_ rhs: C) -> Bool {
  9. return lhs <= rhs
  10. }
  11. prefix func > <C : Comparable>(lhs: C)(_ rhs: C) -> Bool {
  12. return rhs > lhs
  13. }
  14. prefix func >= <C : Comparable>(lhs: C)(_ rhs: C) -> Bool {
  15. return rhs >= lhs
  16. }
  17.  
  18.  
  19. [1, 2, 3, 4, 5].filter(4<) // [5]
  20.  
  21. prefix operator ~= {}
  22. postfix operator ~= {}
  23.  
  24. prefix func ~=<T>(lhs: _OptionalNilComparisonType)(_ rhs: T?) -> Bool {
  25. return lhs ~= rhs
  26. }
  27.  
  28. prefix func ~=<T : Equatable>(a: T)( _ b: T) -> Bool {
  29. return a ~= b
  30. }
  31.  
  32. prefix func ~=<I : ForwardIndexType where I : Comparable>(pattern: Range<I>)(_ value: I) -> Bool {
  33. return pattern ~= value
  34. }
  35.  
  36. prefix func ~=<I : IntervalType>(pattern: I)(_ value: I.Bound) -> Bool {
  37. return pattern ~= value
  38. }
  39.  
  40. postfix func ~=<T>(lhs: _OptionalNilComparisonType)(_ rhs: T?) -> Bool {
  41. return lhs ~= rhs
  42. }
  43.  
  44. postfix func ~=<T : Equatable>(a: T)( _ b: T) -> Bool {
  45. return a ~= b
  46. }
  47.  
  48. postfix func ~=<I : ForwardIndexType where I : Comparable>(pattern: Range<I>)(_ value: I) -> Bool {
  49. return pattern ~= value
  50. }
  51.  
  52. postfix func ~=<I : IntervalType>(pattern: I)(_ value: I.Bound) -> Bool {
  53. return pattern ~= value
  54. }
  55.  
  56. prefix operator == {}
  57. postfix operator == {}
  58.  
  59. prefix func == <E : Equatable>(lhs: E)(_ rhs: E) -> Bool {
  60. return lhs == rhs
  61. }
  62. postfix func == <E : Equatable>(lhs: E)(_ rhs: E) -> Bool {
  63. return lhs == rhs
  64. }
  65.  
  66. (0..<100).filter((5..<15)~=) // [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
  67. (0..<10 ).filter(==5) // [5]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement