public void Deconstruct_Returns_Item_And_Index() { var indexedItem = new ItemWithIndex <int>(42, 5); var(item, index) = indexedItem; item.Should().Be(42); index.Should().Be(5); }
static string ConvertLetter(ItemWithIndex <string> s) { if (s.Item == ".") { return("_"); } if (s.Item.ToLower() == s.Item) { return(s.Item); } if (s.Index != 0) { return("_" + s.Item.ToLower()); } return(s.Item.ToLower()); }
public static ItemWithIndex <T>?BinarySearch <T>(this IList <T> collection, Func <ItemWithIndex <T>, int> getDirection) { var left = 0; var right = collection.Count - 1; var mid = 0; while (left < right) { mid = (left + right) / 2; var item = collection[mid]; var point = new ItemWithIndex <T> { Item = item, Index = mid, }; var direction = getDirection(point); if (direction > 0) { left = mid + 1; } else if (direction == 0) { return(point); } else { right = mid; } } if (mid == left) { return(null); } var lastPoint = new ItemWithIndex <T> { Item = collection[left], Index = left, }; return(getDirection(lastPoint) == 0 ? lastPoint : (ItemWithIndex <T>?)null); }
static bool HaveSameIndexAndItem <T>(ItemWithIndex <T> x, ItemWithIndex <T> y) { return(x.Index == y.Index && EqualityComparer <T> .Default.Equals(x.Item, y.Item)); }