Skip to content

Commit 0613641

Browse files
committed
Deconstruct added to IndexedItem
1 parent c78f2d7 commit 0613641

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

CodeJam.Main.Tests/Collections/Enumerable/EnumerableExtensionTests.With.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public void IndexTest()
1818
for (var n = 1; n < 10; n++)
1919
{
2020
var list = Enumerable.Range(0, n).WithIndex().ToArray();
21-
foreach (var value in list)
22-
Assert.AreEqual(value.Item, value.Index, "#Index");
21+
foreach (var (index, item) in list)
22+
Assert.AreEqual(item, index, "#Index");
2323

2424
Assert.IsTrue(list[0].IsFirst, "#IsFirst");
2525
Assert.IsTrue(list.Last().IsLast, "#IsLast");

CodeJam.Main/Collections/Enumerable/IndexedItem.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,36 @@ public IndexedItem(T item, int index, bool isFirst, bool isLast) : this()
5959
IsLast = isLast;
6060
}
6161

62+
/// <summary>
63+
/// Deconstructs instance.
64+
/// </summary>
65+
public void Deconstruct(out int index, out T item)
66+
{
67+
index = Index;
68+
item = Item;
69+
}
70+
71+
/// <summary>
72+
/// Deconstructs instance.
73+
/// </summary>
74+
public void Deconstruct(out int index, out T item, out bool isFirst)
75+
{
76+
index = Index;
77+
item = Item;
78+
isFirst = IsFirst;
79+
}
80+
81+
/// <summary>
82+
/// Deconstructs instance.
83+
/// </summary>
84+
public void Deconstruct(out int index, out T item, out bool isFirst, out bool isLast)
85+
{
86+
index = Index;
87+
item = Item;
88+
isFirst = IsFirst;
89+
isLast = IsLast;
90+
}
91+
6292
#region Equality members
6393
/// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
6494
/// <returns>

0 commit comments

Comments
 (0)