YAPC::EU 2018 Glasgow Update!
This commit is contained in:
parent
22f33d4004
commit
4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions
1
Task/Array-concatenation/8th/array-concatenation.8th
Normal file
1
Task/Array-concatenation/8th/array-concatenation.8th
Normal file
|
|
@ -0,0 +1 @@
|
|||
[1,2,3] [4,5,6] a:+ .
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
import extensions.
|
||||
|
||||
public program =
|
||||
public program
|
||||
[
|
||||
var a := (1,2,3).
|
||||
var b := (4,5).
|
||||
|
||||
console printLine("(",a,") + (",b,") = (",a + b,")"); readChar.
|
||||
].
|
||||
console printLine("(",a,") + (",b,") = (",a + b,")"); readChar
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,8 +1,18 @@
|
|||
# the prefix:<|> operator (called "slip") can be used to interpolate arrays into a list:
|
||||
sub cat-arrays(@a, @b) {
|
||||
|@a, |@b
|
||||
}
|
||||
my @array1 = 1, 2, 3;
|
||||
my @array2 = 4, 5, 6;
|
||||
|
||||
my @a1 = (1,2,3);
|
||||
my @a2 = (2,3,4);
|
||||
cat-arrays(@a1,@a2).join(", ").say;
|
||||
# If you want to concatenate two array to form a third,
|
||||
# either use the slip operator "|", to flatten each array.
|
||||
|
||||
my @array3 = |@array1, |@array2;
|
||||
say @array3;
|
||||
|
||||
# or just flatten both arrays in one fell swoop
|
||||
|
||||
@array3 = flat @array1, @array2;
|
||||
say @array3;
|
||||
|
||||
# On the other hand, if you just want to add the elements
|
||||
# of the second array to the first, use the .append method.
|
||||
|
||||
say @array1.append: @array2;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue