| 1 |
/* |
| 2 |
Copyright 2015 Google Inc. All rights reserved. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
local arr = std.range(5, 8); |
| 18 |
{ |
| 19 |
array_comprehensions: { |
| 20 |
higher: [x + 3 for x in arr], |
| 21 |
lower: [x - 3 for x in arr], |
| 22 |
evens: [x for x in arr if x % 2 == 0], |
| 23 |
odds: [x for x in arr if x % 2 == 1], |
| 24 |
evens_and_odds: [ |
| 25 |
'%d-%d' % [x, y] |
| 26 |
for x in arr |
| 27 |
if x % 2 == 0 |
| 28 |
for y in arr |
| 29 |
if y % 2 == 1 |
| 30 |
], |
| 31 |
}, |
| 32 |
object_comprehensions: { |
| 33 |
evens: { |
| 34 |
['f' + x]: true |
| 35 |
for x in arr |
| 36 |
if x % 2 == 0 |
| 37 |
}, |
| 38 |
// Use object composition (+) to add in |
| 39 |
// static fields: |
| 40 |
mixture: { |
| 41 |
f: 1, |
| 42 |
g: 2, |
| 43 |
} + { |
| 44 |
[x]: 0 |
| 45 |
for x in ['a', 'b', 'c'] |
| 46 |
}, |
| 47 |
}, |
| 48 |
} |