Skip to content

Latest commit

 

History

History
58 lines (39 loc) · 1.4 KB

File metadata and controls

58 lines (39 loc) · 1.4 KB

UnShift<T> class method

Project: Array Utilities Unit

Unit: DelphiDabbler.Lib.ArrayUtils

Record: TArrayUtils

Applies to: ~>0.1

class procedure UnShift<T>(var A: TArray<T>; const AValue: T);
  static;

Description

Prepends a value to a given array

The length of the array is increased by one.

Parameters:

  • A - Array to which the element is to be added. The array is updated in place when the element is added.

  • AValue - The element to be added to the array.

Example

This example prepends three elements to a previously empty string array.

procedure UnShift_Eg;
var
  A, Expected: TArray<string>;
begin
  A := TArray<string>.Create();

  TArrayUtils.UnShift<string>(A, 'foo');
  Expected := TArray<string>.Create('foo');
  Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));

  TArrayUtils.UnShift<string>(A, 'bar');
  Expected := TArray<string>.Create('bar', 'foo');
  Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));

  TArrayUtils.UnShift<string>(A, 'baz');
  Expected := TArray<string>.Create('baz', 'bar', 'foo' );
  Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));
end;

See Also