mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-04-11 03:00:13 -04:00
adding 'by' to array comprehensions
This commit is contained in:
@@ -848,8 +848,9 @@ module CoffeeScript
|
|||||||
for_part = "#{index_var}=0, #{source.compile(o.merge(:index => ivar, :step => @step))}, #{index_var}++"
|
for_part = "#{index_var}=0, #{source.compile(o.merge(:index => ivar, :step => @step))}, #{index_var}++"
|
||||||
else
|
else
|
||||||
index_var = nil
|
index_var = nil
|
||||||
source_part = "#{svar} = #{source.compile(o)};\n#{idt}"
|
source_part = "#{svar} = #{@source.compile(o)};\n#{idt}"
|
||||||
for_part = @object ? "#{ivar} in #{svar}" : "#{ivar} = 0; #{ivar} < #{svar}.length; #{ivar}++"
|
step_part = @step ? "#{ivar} += #{@step.compile(o)}" : "#{ivar}++"
|
||||||
|
for_part = @object ? "#{ivar} in #{svar}" : "#{ivar} = 0; #{ivar} < #{svar}.length; #{step_part}"
|
||||||
var_part = "#{body_dent}#{@name} = #{svar}[#{ivar}];\n" if @name
|
var_part = "#{body_dent}#{@name} = #{svar}[#{ivar}];\n" if @name
|
||||||
# body.unshift(AssignNode.new(@name, ValueNode.new(svar, [IndexNode.new(ivar)]))) if @name
|
# body.unshift(AssignNode.new(@name, ValueNode.new(svar, [IndexNode.new(ivar)]))) if @name
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -40,3 +40,9 @@ for method in methods
|
|||||||
print obj.one() is "I'm one"
|
print obj.one() is "I'm one"
|
||||||
print obj.two() is "I'm two"
|
print obj.two() is "I'm two"
|
||||||
print obj.three() is "I'm three"
|
print obj.three() is "I'm three"
|
||||||
|
|
||||||
|
|
||||||
|
# Steps should work for array comprehensions.
|
||||||
|
|
||||||
|
array: [0..10]
|
||||||
|
print num % 2 is 0 for num in array by 2
|
||||||
|
|||||||
Reference in New Issue
Block a user