using 'where' for array comprehension filtering, after kamatsu's suggestion -- execution tests pass now with significant whitespace

This commit is contained in:
Jeremy Ashkenas
2009-12-29 08:52:26 -05:00
parent cea417de02
commit 3fbb870d01
6 changed files with 26 additions and 21 deletions

View File

@@ -1,5 +1,5 @@
nums: n * n for n in [1, 2, 3] if n % 2 isnt 0.
results: n * 2 for n in nums.
nums: n * n for n in [1, 2, 3] where n % 2 isnt 0
results: n * 2 for n in nums
# next: for n in [1, 2, 3] if n % 2 isnt 0
# print('hi') if false

View File

@@ -1,6 +1,7 @@
func: =>
a: 3
b: []
while a >= 0
b.push('o')
a--
@@ -20,7 +21,7 @@ func: =>
text = c.text
}
c.list: l for l in d.text.split('') if l is '-'
c.list: l for l in d.text.split('') where l is '-'
c.single: c.list[1..1][0]

View File

@@ -1,6 +1,6 @@
nums: i * 3 for i in [1..3].
nums: i * 3 for i in [1..3]
negs: x for x in [-20..-10].
negs: x for x in [-20..-10]
negs: negs[0..2]
result: nums.concat(negs).join(', ')