Loop over multiple arrays simultaneously: Difference between revisions
Content added Content deleted
m (→{{header|J}}) |
(Add lang example) |
||
Line 2,436: | Line 2,436: | ||
s |
s |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|Lang}}== |
|||
<syntaxhighlight lang="lang"> |
|||
$a $= [a\e, b\e, c\e] |
|||
$b $= [A\e, B\e, C\e] |
|||
$c $= [1, 2, 3] |
|||
# Repeat loop |
|||
$i |
|||
repeat($[i], fn.len($a)) { |
|||
fn.println(parser.op($a[$i] ||| $b[$i] ||| $c[$i])) |
|||
} |
|||
fn.println() |
|||
# Foreach loop with zip and reduce |
|||
$ele |
|||
foreach($[ele], fn.arrayZip($a, $b, $c)) { |
|||
fn.println(fn.arrayReduce($ele, \e, fn.concat)) |
|||
} |
|||
fn.println() |
|||
# Foreach function with combinator |
|||
fn.arrayForEach(fn.arrayZip($a, $b, $c), fn.combB(fn.println, fn.combC3(fn.arrayReduce, fn.concat, \e)))s |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
aA1 |
|||
bB2 |
|||
cC3 |
|||
aA1 |
|||
bB2 |
|||
cC3 |
|||
aA1 |
|||
bB2 |
|||
cC3 |
|||
</pre> |
|||
=={{header|LFE}}== |
=={{header|LFE}}== |