예제 #1
0
        static void UseDemoClass()
        {
            DemoClass           c  = new DemoClass(3);
            FastFunc <int, int> ff = c.CurriedStyle(4);
            int result             = ff.Invoke(5);

            Console.WriteLine("Curried Style Result {0}", result);
            result = c.TupleStyle(4, 5);
            Console.WriteLine("Tuple Style Result {0}", result);
        }
예제 #2
0
        public static Async <T> UnblockViaNewThread <T>(FastFunc <Unit, T> f)
        {
            var type       = typeof(FileExtensions);
            var methodInfo = type.GetMethod("UnblockViaNewThread", BindingFlags.NonPublic | BindingFlags.Static);

            var genericArguments  = new[] { typeof(T) };
            var genericMethodInfo = methodInfo.MakeGenericMethod(genericArguments);

            return(genericMethodInfo.Invoke(null, new[] { f }) as Async <T>);
        }
예제 #3
0
        public void foldl0()
        {
            string        seed   = "hi mom";
            List <string> values = Helper <string> .mkList();

            FastFunc <string, FastFunc <string, string> > fn =
                FuncConvert.ToFastFunc((Converter <string, string, string>) delegate(string a, string b) { throw new Exception("should never be invoked"); });

            string result = Zumbro.foldl <string, string>(fn, seed, values);

            Assert.AreEqual(seed, result);
        }
예제 #4
0
        public void foldl1()
        {
            int        seed   = 64;
            List <int> values = Helper <int> .mkList(4, 2, 4);

            FastFunc <int, FastFunc <int, int> > fn =
                FuncConvert.ToFastFunc((Converter <int, int, int>) delegate(int a, int b) { return(a / b); });

            int result = Zumbro.foldl <int, int>(fn, seed, values);

            Assert.AreEqual(2, result);
        }
    public T Invoke(FastFunc <T, int> f, int bla)
    {
        if (cache == null)
        {
            cache = new MyDict <int, T> ();
        }

        T value = f.Invoke(bla);

        cache.Add(bla, value);

        return(value);
    }
예제 #6
0
        public void map()
        {
            FastFunc <int, int> fn =
                FuncConvert.ToFastFunc((Converter <int, int>) delegate(int a) { return(a * a); });

            List <int> vals = Helper <int> .mkList(1, 2, 3);

            List <int> res = Zumbro.map <int, int>(fn, vals);

            Assert.AreEqual(res.Length, 3);
            Assert.AreEqual(1, res.Head);
            Assert.AreEqual(4, res.Tail.Head);
            Assert.AreEqual(9, res.Tail.Tail.Head);
        }
예제 #7
0
        static void MapOne()
        {
            List <string> l = new List <string>(
                new string[] { "Stefany", "Oussama",
                               "Sebastien", "Frederik" });
            Converter <string, bool> pred =
                delegate(string s) { return(s.StartsWith("S")); };
            FastFunc <string, bool> ff =
                FuncConvert.ToFastFunc <string, bool>(pred);
            IEnumerable <string> ie =
                DemoModule.filterStringList(ff, l);

            foreach (string s in ie)
            {
                Console.WriteLine(s);
            }
        }