Пример #1
0
        public void tap_with_action_gives_back_initial_object()
        {
            var x = new Dictionary<string, object>();
            x["Foo"] = 1;
            x["Bar"] = 2;
            var result = x.Tap((item) => {
                int sum = (int)item["Foo"] + (int)item["Bar"];
            });

            Assert.Same(x, result);
            Assert.Equal(1, result["Foo"]);
            Assert.Equal(2, result["Bar"]);
        }
Пример #2
0
        public void tap_with_func_gives_back_modified_object_same_reference()
        {
            var x = new Dictionary<string, object>();
            x["Foo"] = 1;
            x["Bar"] = 2;
            var result = x.Tap((item) => {
                item["Foo"] = 12;
                item["Bar"] = 13;
                return item;
            });

            Assert.Same(x, result);
            Assert.Equal(12, result["Foo"]);
            Assert.Equal(13, result["Bar"]);
            Assert.Equal(12, x["Foo"]);
            Assert.Equal(13, x["Bar"]);
        }