Skip to content

Commit

Permalink
[std] allow ReadOnlyArray.concat(ReadOnlyArray) (HaxeFoundation#9710)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gama11 authored Jul 14, 2020
1 parent 194cccd commit 3dff723
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
19 changes: 18 additions & 1 deletion std/haxe/ds/ReadOnlyArray.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ package haxe.ds;
Other code holding a reference to the underlying `Array` can still modify it,
and the reference can be obtained with a `cast`.
**/
@:forward(concat, copy, filter, indexOf, iterator, keyValueIterator, join, lastIndexOf, map, slice, contains, toString)
@:forward(copy, filter, indexOf, iterator, keyValueIterator, join, lastIndexOf, map, slice, contains, toString)
abstract ReadOnlyArray<T>(Array<T>) from Array<T> to Iterable<T> {
/**
The length of `this` Array.
Expand All @@ -42,4 +42,21 @@ abstract ReadOnlyArray<T>(Array<T>) from Array<T> to Iterable<T> {

@:arrayAccess inline function get(i:Int)
return this[i];

/**
Returns a new Array by appending the elements of `a` to the elements of
`this` Array.
This operation does not modify `this` Array.
If `a` is the empty Array `[]`, a copy of `this` Array is returned.
The length of the returned Array is equal to the sum of `this.length`
and `a.length`.
If `a` is `null`, the result is unspecified.
**/
public inline function concat(a:ReadOnlyArray<T>):Array<T> {
return this.concat(cast a);
}
}
11 changes: 11 additions & 0 deletions tests/unit/src/unit/issues/Issue9710.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package unit.issues;

import haxe.ds.ReadOnlyArray;

class Issue9710 extends unit.Test {
function test() {
var a:ReadOnlyArray<Int> = [1];
var b:ReadOnlyArray<Int> = [2];
aeq([1, 2], a.concat(b));
}
}

0 comments on commit 3dff723

Please sign in to comment.