This is a new site that's currently running on alpha code. There are going to be bugs. If you discover any, please report them on the site's issues page (GitHub account required). Thanks.
Warning: Many URLs are going to change. Refer to the README file to discover which library project's documentation has been completed.
Project: Array Utilities Unit
Unit: DelphiDabbler.Lib.ArrayUtils
Record: TArrayUtils
Applies to: ~>0.1
class function Shift<T>(var A: TArray<T>): T;
static;
Removes the first element from a non-empty array.
The length of the array is reduced by one.
Parameters:
Returns:
Preconditions:
This example shifts elements from an array until the array is empty.
procedure Shift_Eg;
var
A, Expected: TArray<string>;
begin
A := TArray<string>.Create('a', 'stitch', 'in', 'time');
Expected := TArray<string>.Create('stitch', 'in', 'time');
Assert(TArrayUtils.Shift<string>(A) = 'a');
Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));
Expected := TArray<string>.Create('in', 'time');
Assert(TArrayUtils.Shift<string>(A) = 'stitch');
Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));
Expected := TArray<string>.Create('time');
Assert(TArrayUtils.Shift<string>(A) = 'in');
Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));
Expected := TArray<string>.Create();
Assert(TArrayUtils.Shift<string>(A) = 'time');
Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));
end;