Skip to content

Instantly share code, notes, and snippets.

@sisoje
Last active February 7, 2019 14:55
Show Gist options
  • Save sisoje/b72c003300f0693c2e419c9a1683d38d to your computer and use it in GitHub Desktop.
Save sisoje/b72c003300f0693c2e419c9a1683d38d to your computer and use it in GitHub Desktop.
struct Person {
let name: String
let age: Int
}
struct Payment {
let currency: String
let amount: Double
}
// persons named John older than 18
let predicate1 = \Person.name == "John" && \Person.age >= 18
// payments in EUR, USD or GBP greater than 1000
let predicate2 = \Payment.currency === ["EUR", "USD", "GBP"] && \Payment.amount > 1000
// doesn't compile - value type does not match
let predicate3 = \Payment.currency == 1000
// doesn't compile - root type between predicates does not match
let predicate4 = \Payment.currency == "EUR" && \Person.age >= 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment