예제 #1
0
        public NodeInt Map(Func <int, int> func)
        {
            NodeInt result = new NodeInt();

            Iterate((v) => result.Add(func(v)));
            return(result);
        }
예제 #2
0
        public ListInt Filter(Func <int, bool> func)
        {
            NodeInt result = new NodeInt();

            Iterate((v) => { if (func(v))
                             {
                                 result.Add(v);
                             }
                    });
            return(result.IsEmpty ? (ListInt) new EmptyInt() : result);
        }
예제 #3
0
        /// <summary> 2.1.4 </summary>
        private static void TestNodeInt()
        {
            using (NodeInt n = new NodeInt(1, 2, 3, 4, 5))
            {
                Write("Collection:\t");
                n.Iterate(WriteNum);
                Write(Environment.NewLine);

                Write("Filter (>2):\t");
                n.Filter((v) => v > 2).Iterate(WriteNum);
                Write(Environment.NewLine);

                Write("Map (+1):\t");
                n.Map((v) => v + 1).Iterate(WriteNum);
                Write(Environment.NewLine);
            }
        }