Skip to content
Yuki Kimoto edited this page Feb 23, 2024 · 3 revisions

How to merge two arrays

use IntList;

my $array1 = [1, 2];
my $array2 = [3, 4];

my $list = IntList->new($array1);
for my $elem (@$array2) { $list->push($elem); }
my $merged_array = $list->to_array;

Recent versions of SPVM has methods for merge arrays.

use Array;

my $array1 = [1, 2];
my $array2 = [3, 4];

my $merged_array = Array->merge_int($array1, $array2);

How to create a constant string array

use Immutable::StringList;

my $constant_strings = Immutable::StringList->new([
  "foo",
  "bar",
  "baz",
]);