@@ -19,6 +19,49 @@ partial class EnumerableExtensions
1919 private const string _listTooShortMsg = "The list is too short." ;
2020 private const string _enumTooShortMsg = "The enumerable is too short." ;
2121
22+ /// <summary>
23+ /// Deconstructs 1 item of the <paramref name="array"/>.
24+ /// </summary>
25+ [ Pure ]
26+ public static void Deconstruct < T > (
27+ [ NotNull ] this T [ ] array ,
28+ out T item1 )
29+ {
30+ Code . NotNull ( array , nameof ( array ) ) ;
31+ Code . AssertArgument ( array . Length >= 1 , nameof ( array ) , _arrayTooShortMsg ) ;
32+
33+ item1 = array [ 0 ] ;
34+ }
35+
36+ /// <summary>
37+ /// Deconstructs 1 items of the <paramref name="list"/>.
38+ /// </summary>
39+ [ Pure ]
40+ public static void Deconstruct < T > (
41+ [ NotNull ] this IList < T > list ,
42+ out T item1 )
43+ {
44+ Code . NotNull ( list , nameof ( list ) ) ;
45+ Code . AssertArgument ( list . Count >= 1 , nameof ( list ) , _listTooShortMsg ) ;
46+
47+ item1 = list [ 0 ] ;
48+ }
49+
50+ /// <summary>
51+ /// Deconstructs 1 items of the <paramref name="enumerable"/>.
52+ /// </summary>
53+ [ Pure ]
54+ public static void Deconstruct < T > (
55+ [ NotNull ] this IEnumerable < T > enumerable ,
56+ out T item1 )
57+ {
58+ Code . NotNull ( enumerable , nameof ( enumerable ) ) ;
59+
60+ using var enumerator = enumerable . GetEnumerator ( ) ;
61+ Code . AssertArgument ( enumerator . MoveNext ( ) , nameof ( enumerable ) , _enumTooShortMsg ) ;
62+ item1 = enumerator . Current ;
63+ }
64+
2265 /// <summary>
2366 /// Deconstructs 2 items of the <paramref name="array"/>.
2467 /// </summary>
0 commit comments