aboutsummaryrefslogtreecommitdiff
path: root/doc/docs/doc/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'doc/docs/doc/README.md')
-rwxr-xr-xdoc/docs/doc/README.md38
1 files changed, 38 insertions, 0 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md
index ad26be5..2a3047a 100755
--- a/doc/docs/doc/README.md
+++ b/doc/docs/doc/README.md
@@ -595,6 +595,23 @@ tab[] = "Value"
595</pre> 595</pre>
596</YueDisplay> 596</YueDisplay>
597 597
598You can also use the spread operator `...` to append all elements from one list to another:
599
600```moonscript
601tbA = [1, 2, 3]
602tbB = [4, 5, 6]
603tbA[] = ...tbB
604-- tbA is now [1, 2, 3, 4, 5, 6]
605```
606<YueDisplay>
607<pre>
608tbA = [1, 2, 3]
609tbB = [4, 5, 6]
610tbA[] = ...tbB
611-- tbA is now [1, 2, 3, 4, 5, 6]
612</pre>
613</YueDisplay>
614
598### Table Spreading 615### Table Spreading
599 616
600You can concatenate array tables or hash tables using spread operator `...` before expressions in table literals. 617You can concatenate array tables or hash tables using spread operator `...` before expressions in table literals.
@@ -2465,6 +2482,27 @@ doubled = [item * 2 for item in *items]
2465</pre> 2482</pre>
2466</YueDisplay> 2483</YueDisplay>
2467 2484
2485In list comprehensions, you can also use the spread operator `...` to flatten nested lists, achieving a flat map effect:
2486
2487```moonscript
2488data =
2489 a: {1,2,3}
2490 b: {4,5,6}
2491
2492flat = [...v for k,v in pairs data]
2493-- flat is now [1, 2, 3, 4, 5, 6]
2494```
2495<YueDisplay>
2496<pre>
2497data =
2498 a: {1,2,3}
2499 b: {4,5,6}
2500
2501flat = [...v for k,v in pairs data]
2502-- flat is now [1, 2, 3, 4, 5, 6]
2503</pre>
2504</YueDisplay>
2505
2468The for and when clauses can be chained as much as desired. The only requirement is that a comprehension has at least one for clause. 2506The for and when clauses can be chained as much as desired. The only requirement is that a comprehension has at least one for clause.
2469 2507
2470Using multiple for clauses is the same as using nested loops: 2508Using multiple for clauses is the same as using nested loops: