Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
- Clojure
- C++
- C#
- C#
- D
- Dart
- Elixir
- Elixir
- Fortran
- Go
- Haskell
- JS
- JS
- Java
- Java
- Java
- Lisp
- PHP
- Pascal
- Perl
- Python
- Python
- Ruby
- Ruby
- Rust
- Scheme
;; for side effects
(doseq [x (concat items1 items2)]
(println x))
concat concatenates two or more sequences https://clojuredocs.org/clojure.core/concat
doseq for side effects. Alternatively for to produce a new sequence https://clojuredocs.org/clojure.core/doseq
https://clojuredocs.org/clojure.core/for
doseq for side effects. Alternatively for to produce a new sequence https://clojuredocs.org/clojure.core/doseq
https://clojuredocs.org/clojure.core/for
void print_seq(const auto& ...xs)
{
(std::for_each(std::begin(xs), std::end(xs),
[](const auto& x) { std::cout << x; }), ...);
}
std::list xs { "hi", "there", "world" }, ys { "lo" "thar" };
print_seq(xs, ys);
items1.ForEach(Console.WriteLine);
items2.ForEach(Console.WriteLine);
chain(items1, items2).each!writeln;
items1.forEach(print);
items2.forEach(print);
def main(items1, items2) do
Enum.each(items1, &IO.puts/1)
Enum.each(items2, &IO.puts/1)
end
items1 ++ items2 |> Enum.each(&IO.puts/1)
print *,items1,items2
No need to iterate - the language does that on its own.
for _, v := range items1 {
fmt.Println(v)
}
for _, v := range items2 {
fmt.Println(v)
}
No magic sugar. Write 2 loops.
mapM_ print $ items1 ++ items2
$ is the function application operator of Haskell to eliminate annoying parentheses.
E.g., f $ g x y z == f (g x y z)
E.g., f $ g x y z == f (g x y z)
for (let item of items1) console.log(item)
for (let item of items2) console.log(item)
items1.concat(items2).forEach(console.log)
uses Array.concat(...) to join items.
Use .map(), .filter(), .reduce(), .forEach() to process.
Use .map(), .filter(), .reduce(), .forEach() to process.
(map nil #'print (append items1 items))
# beginner style
foreach( $items1 as $item ) print "$item\n";
foreach( $items2 as $item ) print "$item\n";
# five times faster
print implode("\n", $items1)."\n".implode("\n", $items2)."\n" ;
In these simple examples, $items1 and $items2 must be arrays, and their elements must be scalar data types (numbers, strings, booleans).
for i := 0 to items1.Count-1 do writeln(items1[i]);
for i := 0 to items2.Count-1 do writeln(items2[i]);
print for @items1, @items2;
for x in items1 + items2:
print(x)
items1.chain(items2).each{|item| puts item}
chain is added to Ruby in version 2.6
[items1, items2].each{|ar| ar.each{|item| p item }}
(map (lambda (x)
(display x)
(newline))
(append items1 items2))