-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/flatcollections-array/FlatArray/FlatArray.T/Functional/Functional.Cast.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace System; | ||
|
||
partial struct FlatArray<T> | ||
{ | ||
// TODO: Add the tests and make public | ||
internal FlatArray<TResult> Cast<TResult>() | ||
{ | ||
if (length == default) | ||
{ | ||
return default; | ||
} | ||
|
||
if (items is TResult[] resultItems) | ||
{ | ||
return new(length, resultItems); | ||
} | ||
|
||
resultItems = new TResult[length]; | ||
|
||
var counter = 0; | ||
do | ||
{ | ||
resultItems[counter] = (TResult)(object)items![counter]!; | ||
} | ||
while (++counter < resultItems.Length); | ||
|
||
return new(resultItems, default); | ||
} | ||
} |