Esempio n. 1
0
 public void AllValues()
 {
     ReadOnlyList.AllBytes().Select(e => (int)e).AssertListEquals(Enumerable.Range(Byte.MinValue, Byte.MaxValue + 1 - Byte.MinValue));
     ReadOnlyList.AllSignedBytes().Select(e => (int)e).AssertListEquals(Enumerable.Range(SByte.MinValue, SByte.MaxValue + 1 - SByte.MinValue));
     ReadOnlyList.AllUnsigned16BitIntegers().Select(e => (int)e).AssertListEquals(Enumerable.Range(UInt16.MinValue, UInt16.MaxValue + 1 - UInt16.MinValue));
     ReadOnlyList.AllSigned16BitIntegers().Select(e => (int)e).AssertListEquals(Enumerable.Range(Int16.MinValue, Int16.MaxValue + 1 - Int16.MinValue));
     ReadOnlyList.AllBools().AssertListEquals(false, true);
 }
Esempio n. 2
0
        public MainWindow()
        {
            InitializeComponent();

            // all of these examples create lists with constant-time operations that don't get more expensive as the list grows.
            // these operations include:
            // - creating the list
            // - determining the number of items in the list
            // - accessing items by index in the list
            // - advancing an enumeration of the list
            // also, only a constant amount of memory is used per list (except for what's used to show their items as text)

            Show("Naturals less than A", (a, b, c) =>
                 a.Range());

            Show("B", (a, b, c) =>
                 b);

            Show("C", (a, b, c) =>
                 c);

            Show("Last A bytes", (a, b, c) =>
                 ReadOnlyList.AllBytes().TakeLast(a));

            Show("B reversed", (a, b, c) =>
                 b.Reverse());

            Show("Take up to A of C", (a, b, c) =>
                 c.Take(a));

            Show("Stride to a million by A", (a, b, c) =>
                 1000000.Range().Stride(a));

            Show("C with item letters sorted", (a, b, c) =>
                 c.Select(e => new String(e.OrderBy(character => character).ToArray())));

            Show("Pairwise equals of B,C", (a, b, c) =>
                 b.Zip(c, (itemB, itemC) => itemB == itemC));

            Show("Skip first and last A of B", (a, b, c) =>
                 b.Skip(a).SkipLast(a));

            Show("Skip EXACTLY last A of B", (a, b, c) =>
                 b.SkipLastRequire(a));

            Show("Partition C by A, concatenating", (a, b, c) =>
                 from g in c.Partition(a)
                 select String.Join("", g));

            Show("Cube map", (a, b, c) => {
                var count     = 100;
                var squareMap = new AnonymousReadOnlyDictionary <int, int>(
                    count.Range(),
                    (int key, out int value) => {
                    value = key * key;
                    return(key >= 0 && key < count);
                });
                var cubeMap = squareMap.SelectValue(e => e.Key * e.Value);
                return(cubeMap); // treated as an IReadOnlyCollection<KeyValuePair<int, int>>
            });
        }