예제 #1
0
        public void Apply_Six()
        {
            var func = Curry.Apply <int, int, int, int, int, int, int>((a, b, c, d, e, f) => a + b + c + d + e + f);

            int value = -1;

            value = func(1)(0)(0)(0)(0)(0);
            Assert.AreEqual(1, value);

            value = func(1)(2)(0)(0)(0)(0);
            Assert.AreEqual(3, value);

            value = func(1)(2)(3)(0)(0)(0);
            Assert.AreEqual(6, value);

            value = func(1)(2)(3)(4)(0)(0);
            Assert.AreEqual(10, value);

            value = func(1)(2)(3)(4)(5)(0);
            Assert.AreEqual(15, value);

            value = func(1)(2)(3)(4)(5)(6);
            Assert.AreEqual(21, value);
        }
예제 #2
0
 public ActionResult Delete(int CategoryId, int CurryId)
 {
     if (CategoryId > 0)
     {
         //write a LINQ query to select a category with an ID that is the same as the parameter CategoryId
         Ingredients category = db.Ingredients.First(val => val.ID == CategoryId);
         if (category == null)
         {
             return(HttpNotFound());
         }
         if (CurryId > 0)
         {
             //write a LINQ query to select a movie with an ID that is the same as the parameter MovieId
             Curry curry = db.Curries.First(val => val.ID == CurryId);
             if (curry == null)
             {
                 return(HttpNotFound());
             }
             curry.Categories.Remove(category);
             db.SaveChanges();
         }
     }
     return(View("Index", CreateAssignCategoryViewModel(CurryId)));
 }
예제 #3
0
 public static Func <State, State> UpdateProcessing(Event processing)
 {
     return(Curry <Event, State, State> .New(UpdateProcessing)(processing));
 }
예제 #4
0
 public static Object LDiv(Object[] args)
 {
     return(Curry.MinTwo(StandardOperators.LDiv, args) ??
            If.Is <Double, Double>(args, (y, x) => y / x) ??
            If.Is <Double[, ], Double>(args, (y, x) => y.Divide(x)));
 }
예제 #5
0
 /// <summary>
 /// Partially apply the first arg to a three parameter function
 /// </summary>
 public static Func <T2, Func <T3, T4> > Apply <T1, T2, T3, T4>(Func <T1, T2, T3, T4> func, T1 arg1)
 {
     return(Curry(func)(arg1));
 }
예제 #6
0
 public static Object Mod(Object[] args)
 {
     return(Curry.MinTwo(StandardOperators.Mod, args) ??
            If.Is <Double, Double>(args, (y, x) => x % y) ??
            If.IsNotNull(args, m => m.ToNumber(), (y, x) => x % y));
 }
예제 #7
0
 public static Func <State, State> OverlayOnEventStoreList(Func <State, ImList <Event> > getEventList)
 {
     return(Curry <Func <State, ImList <Event> >, State, State> .New(OverlayOnEventStoreList)(getEventList));
 }
예제 #8
0
 public static Func <State, State> UpdateGameState(GameState gameState)
 {
     return(Curry <GameState, State, State> .New(UpdateGameState)(gameState));
 }
예제 #9
0
 public static Func <State, State> Curry <T1, T2>(Func <T1, T2, State, State> handler, T1 arg1, T2 arg2)
 {
     return(Curry <T1, T2, State, State> .New(handler)(arg1)(arg2));
 }
예제 #10
0
 public static Object Abs(Object[] args)
 {
     return(Curry.MinOne(StandardOperators.Abs, args) ??
            If.Is <Double[, ]>(args, x => Matrix.Abs(x)) ??
            Math.Abs(args[0].ToNumber()));
 }
예제 #11
0
 public static Object Type(Object[] args)
 {
     return(Curry.MinOne(StandardOperators.Type, args) ?? args[0].ToType());
 }
예제 #12
0
        public void TypeInference_EitherIdConstConst_CorrectType()
        {
            /*
             * id : a -> a
             * dot: (b -> c) -> (a -> b) -> a -> c
             * const - throw away b: a -> b -> a
             * eitherFunc: (a -> b) -> (c -> d) -> (a -> b)
             * eitherFunc: (a -> b) -> (c -> d) -> (c -> d)
             *
             *
             * All with free vars:
             * id: a -> a
             * dot: (b -> c) -> (x -> b) -> x -> c
             * const: y -> z -> y
             * eitherfunc: (d -> e) -> (f -> g) -> (d -> e)
             *             (d -> e) -> (f -> g) -> (f -> g)
             */

            /*
             * (((eitherfunc id) dot) const)
             *
             *  (eitherfunc id)
             *  [(d -> e) -> (f -> g) -> (d -> e)] (a -> a)
             *  [(d -> e) -> (f -> g) -> (f -> g)] (a -> a)
             *
             * Gives:
             *   d ~ a
             *   e ~ a
             * thus:
             * (f -> g) -> (a -> a)
             * (f -> g) -> (f -> g)
             *
             * ((eitherfunc id) dot)
             * [(f -> g) -> (a -> a)] ((b -> c) -> (x -> b) -> x -> c)
             * [(f -> g) -> (f -> g)] (b -> c) -> (x -> b) -> (x -> c)
             *
             * Thus: (f -> g) ~ (b -> c) -> ((x -> b) -> x -> c)
             * thus: f ~ (b -> c)
             *       g ~ ((x -> b) -> (x -> c))
             * thus:
             * (a -> a)
             * (b -> c) -> ((x -> b) -> (x -> c))
             *
             *
             *
             * (((eitherfunc id) dot) const):
             * [(a -> a)] (y -> (z -> y))
             * [(b -> c) -> ((x -> b) -> (x -> c))] (y -> (z -> y))
             *
             * Thus: case 1:
             *     a ~ (y -> (z -> y)
             *     Type is: (y -> z -> y) === typeof(const)
             * case2:
             *     (b -> c) ~  (y -> (z -> y))
             *     thus: b ~ y
             *           c ~ (z -> y)
             *     ((x -> y) -> (x -> (z -> y))))
             *     = ((x -> y) -> x -> z -> y === mix of dot and const
             *
             */

            var a = new Var("a");
            var c = new Var("c");
            var d = new Var("d");


            var e     = Funcs.Either(Funcs.Id, Funcs.Dot, Funcs.Const);
            var types = e.Types.ToList();

            Assert.Equal(Curry.ConstructFrom(c, c, d), types[0]);
            Assert.Equal(Curry.ConstructFrom(
                             c, // RESULT TYPE
                             new Curry(a, c),
                             a, d
                             ), types[1]);
        }
예제 #13
0
 public static Object Transpose(Object[] args)
 {
     return(Curry.MinOne(StandardOperators.Transpose, args) ??
            If.Is <Double[, ]>(args, x => x.Transpose()) ??
            args[0].ToNumber().ToMatrix());
 }
예제 #14
0
 public static Func <State, State> UnpackEventArchivesInRange(long oldestSpawnTime)
 {
     return(Curry <long, State, State> .New(UnpackEventArchivesInRange)(oldestSpawnTime));
 }
예제 #15
0
 public static Func <State, State> UpdateEventStoreProgress(Func <State, string> getProgress)
 {
     return(Curry <Func <State, string>, State, State> .New(UpdateEventStoreProgress)(getProgress));
 }
예제 #16
0
 public static Func <State, State> UpdateEventStoreProgress(string progress)
 {
     return(Curry <string, State, State> .New(Store.UpdateEventStoreProgress)(progress));
 }
예제 #17
0
 public static Func <State, State> UpdateEventStoreList(ImList <Event> eventStoreList)
 {
     return(Curry <ImList <Event>, State, State> .New(UpdateEventStoreList)(eventStoreList));
 }
예제 #18
0
 public static Func <IEnumerable <string>, string> Join(string separator)
 {
     return(Curry <string, IEnumerable <string>, string>(string.Join)(separator));
 }
예제 #19
0
 public static Func <State, State> UpdateEventArchives(ImList <EventArchive> eventArchives)
 {
     return(Curry <ImList <EventArchive>, State, State> .New(UpdateEventArchives)(eventArchives));
 }
예제 #20
0
 protected Object TryCurry(Object[] arguments)
 {
     return(Curry.Min(_maxParameters, _proxy, arguments));
 }
예제 #21
0
 public static Func <State, State> Curry <T>(Func <T, State, State> handler, T arg1)
 {
     return(Curry <T, State, State> .New(handler)(arg1));
 }
예제 #22
0
 /// <summary>
 /// Map Maybe T to Maybe R with mapper of arity 2
 /// by currying
 /// </summary>
 public static Maybe <Func <T2, R> > Map <T1, T2, R>(this Maybe <T1> self, Func <T1, T2, R> mapper) =>
 self.Map(Curry.curry(mapper));
예제 #23
0
 public static Object Pipe(Object[] args)
 {
     return(Curry.MinTwo(StandardOperators.Pipe, args) ??
            If.Is <Function>(args, f => f.Invoke(new[] { args[1] })));
 }
예제 #24
0
 public static Func <State, State> UnpackNewestEventArchive(ImList <EventArchive> eventArchives)
 {
     return(Curry <ImList <EventArchive>, State, State> .New(UnpackNewestEventArchive)(eventArchives));
 }
예제 #25
0
 public static Object Sub(Object[] args)
 {
     return(Curry.MinTwo(StandardOperators.Sub, args) ??
            If.Is <Double, Double>(args, (y, x) => x - y) ??
            If.Is <Double[, ], Double[, ]>(args, (y, x) => x.Subtract(y)));
 }
예제 #26
0
 public static Func <State, State> OverlayOnEventStoreList(ImList <Event> eventList)
 {
     return(Curry <ImList <Event>, State, State> .New(OverlayOnEventStoreList)(eventList));
 }
예제 #27
0
 public static Object RDiv(Object[] args)
 {
     return(Curry.MinTwo(StandardOperators.RDiv, args) ??
            If.Is <Double, Double>(args, (y, x) => x / y) ??
            If.Is <Double, Double[, ]>(args, (y, x) => x.Divide(y)));
 }
예제 #28
0
 public static Func <State, State> UnpackEventArchivesInRange(Func <State, long> getOldestSpawnTime)
 {
     return(Curry <Func <State, long>, State, State> .New(UnpackEventArchivesInRange)(getOldestSpawnTime));
 }