Created
December 9, 2019 00:36
-
-
Save Pzixel/7bfb191cc5f06fb3961214de7132482a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public static class XEnumerable | |
{ | |
public static (T1[], T2[]) Unzip<T1, T2>(this IEnumerable<(T1 x, T2 y)> source) | |
{ | |
if (source is IReadOnlyCollection<(T1, T2)> roc) | |
{ | |
T1[] xs = new T1[roc.Count]; | |
T2[] ys = new T2[roc.Count]; | |
int i = 0; | |
foreach (var (x, y) in source) | |
{ | |
xs[i] = x; | |
ys[i] = y; | |
i++; | |
} | |
return (xs, ys); | |
} | |
var xsList = new List<T1>(); | |
var ysList = new List<T2>(); | |
foreach (var (x, y) in source) | |
{ | |
xsList.Add(x); | |
ysList.Add(y); | |
} | |
return (xsList.ToArray(), ysList.ToArray()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment