-
Notifications
You must be signed in to change notification settings - Fork 2
Syntax
Glen Low edited this page Dec 23, 2015
·
14 revisions
<tr>
<th>Difference</th>
<td><code>age.subtract(beauty)</code></td>
<td><code>age MINUS beauty</code></td>
<td><code>age - beauty</code></td>
</tr>
<tr>
<th>Intersect</th>
<td><code>age.intersect(beauty)</code></td>
<td><code>age INTERSECT beauty</code></td>
<td><code>age & beauty</code></td>
</tr>
<tr>
<th>Nullary Date</th>
<td><code>NSDate()</code></td>
<td colspan="2"><code>now()</code></td>
</tr>
<tr>
<th>Nullary Integer</th>
<td>N.A.</td>
<td colspan="2"><code>random()</code></td>
</tr>
<tr>
<th>Subquery</th>
<td><code>age.filter{ $0 > 42 }</code></td>
<td><code>SUBQUERY(age,</code><br/><code>$x,</code><br/><code>$x > 42)</code></td>
<td><code>subquery(age,</code><br/><code>iterator: x,</code><br/><code>predicate:</code><br/><code>x > 42)</code></td>
</tr>
<tr>
<th rowspan="2">Unary Integer</th>
<td>N.A.</td>
<td colspan="2"><code>randomn(age)</code></td>
</tr>
<tr>
<td colspan="3"><code>~age</code></td>
</tr>
<tr>
<th rowspan="8">Unary Number</th>
<td colspan="3"><code>sqrt(age)</code></td>
</tr>
<tr>
<td colspan="3"><code>log(age)</code></td>
</tr>
<tr>
<td colspan="3"><code>ln(age)</code></td>
</tr>
<tr>
<td colspan="3"><code>exp(age)</code></td>
</tr>
<tr>
<td colspan="3"><code>floor(age)</code></td>
</tr>
<tr>
<td><code>ceil(age)</code></td>
<td><code>ceiling(age)</code></td>
<td><code>ceil(age)</code></td>
</tr>
<tr>
<td colspan="3"><code>abs(age)</code></td>
</tr>
<tr>
<td colspan="3"><code>trunc(age)</code></td>
</tr>
<tr>
<th rowspan="8">Unary Sequence to Number</th>
<td><code>age.reduce(0,</code><br/><code>combine:+)</code></td>
<td colspan="2"><code>sum(age)</code></td>
</tr>
<tr>
<td><code>age.count</code></td>
<td colspan="2"><code>count(age)</code></td>
</tr>
<tr>
<td><code>age.minElement()</code></td>
<td colspan="2">min(age)</code></td>
</tr>
<tr>
<td><code>age.maxElement()</code></td>
<td colspan="2"><code>max(age)</code></td>
</tr>
<tr>
<td>N.A.</td>
<td colspan="2"><code>average(age)</code></td>
</tr>
<tr>
<td>N.A.</td>
<td colspan="2"><code>median(age)</code></td>
</tr>
<tr>
<td>N.A.</td>
<td colspan="2"><code>mode(age)</code></td>
</tr>
<tr>
<td>N.A.</td>
<td colspan="2"><code>stddev(age)</code></td>
</tr>
<tr>
<th rowspan="2">Unary String</th>
<td><code>age.lowercaseString</code></td>
<td colspan="2">lowercase(age)</code></td>
</tr>
<tr>
<td><code>age.uppercaseString</code></td>
<td colspan="2"><code>uppercase(age)</code></td>
</tr>
<tr>
<th>Unary String to Integer</th>
<td><code>age.length</code></td>
<td colspan="2"><code>length(age)</code></td>
</tr>
<tr>
<th>Union</th>
<td><code>age.union(beauty)</code></td>
<td><code>age UNION beauty</code></td>
<td><code>age | beauty</code></td>
</tr>
<tr>
<th>And</th>
<td><code>age > 21</code><br/><code>&& age < 42</code></td>
<td><code>age > 21</code><br/><code>AND age < 42</code></td>
<td><code>age > 21</code><br/><code>&& age < 42</code></td>
</tr>
<tr>
<th rowspan="6">Comparison</th>
<td colspan="3"><code>age < 42</code></td>
</tr>
<tr>
<td colspan="3"><code>age <= 42</code></td>
</tr>
<tr>
<td colspan="3"><code>age > 42</code></td>
</tr>
<tr>
<td colspan="3"><code>age >= 42</code></td>
</tr>
<tr>
<td colspan="3"><code>age == 42</code></td>
</tr>
<tr>
<td colspan="3"><code>age != 42</code></td>
</tr>
<tr>
<th>Not</th>
<td colspan="3"><code>!(age > 42)</code></td>
</tr>
<tr>
<th>Or</th>
<td><code>age > 21</code><br/><code>|| age < 42</code></td>
<td><code>age > 21</code><br/><code>OR age < 42</code></td>
<td><code>age > 21</code><br/><code>|| age < 42</code></td>
</tr>
<tr>
<th rowspan="2">Quantified</th>
<td>N.A.</td>
<td><code>ALL age == 42</code></td>
<td><code>all(age == 42)</code></td>
</tr>
<tr>
<td>N.A.</td>
<td><code>ANY age == 42</code></td>
<td><code>any(age == 42)</code></td>
</tr>
Swift | NSPredicate | PredicatePal | |
---|---|---|---|
Terms | N.A. | ANYKEY |
AnyKey<T> |
N.A. | Block<T> { } |
||
true |
TRUEPREDICATE |
Boolean(true) |
|
false |
FALSEPREDICATE |
Boolean(false) |
|
42 |
Const(42) |
||
"hello" |
Const("hello") |
||
self.age |
age |
Key<T>("age") |
|
self |
SELF |
This<T>() |
|
N.A. | $age |
Var<T>("age") |
|
Binary Index | age[1] |
||
age["one"] |
|||
Binary Integer | age & 42 |
||
age | 42 |
|||
age ^ 42 |
|||
age << 42 |
|||
age >> 42 |
|||
Binary Location to Number |
age .distanceFromLocation (beauty)
|
distanceToLocation: fromLocation: (age, beauty)
|
distance(age, beauty)
|
Binary Number | age + 42 |
||
age - 42 |
|||
age * 42 |
|||
age / 4 |
|||
age % 4 |
modulus:by:(age, 4) |
age % 4 |
|
pow(age, 4) |
age ** 4 |
Missing expressions:
- Keypath-specified expressions:
$age.n
-- no compile-time support as of OS X 10.11 and iOS 9 -
MATCHES
,LIKE
,BEGINSWITH
,ENDWITH
,IN
,CONTAINS
,BETWEEN
-- need to pick suitable operator or function - Predicate options: case insensitive, diacritic insensitive, normalised -- need to pick suitable implementation