Ejemplo n.º 1
0
    public Async <B> On <B>(Fun1 <A, B> fun)
    {
        Async <B> result = new Async <B>();

        if (done)
        {
            if (exn == null)
            {
                result.Supply((B)fun.Apply(value));
            }
        }
        else
        {
            if (on != null)
            {
                Action <A> prev = on;
                on = delegate(A x) { prev(x); result.Supply((B)fun.Apply(x)); };
            }
            else
            {
                active++;
                on = delegate(A x) { result.Supply((B)fun.Apply(x)); };
            }
        }
        return(result);
    }
Ejemplo n.º 2
0
 public static A[] NewArray <A>(int len, Fun1 <int, A> init)
 {
     A[] a = new A[len];
     for (int i = 0; i < len; i++)
     {
         a[i] = (A)init.Apply(i);
     }
     return(a);
 }
Ejemplo n.º 3
0
 public static A Catch <A>(Fun0 <A> action, Fun1 <Exception, A> handler)
 {
     try
     {
         return((A)action.Apply());
     }
     catch (Exception exn)
     {
         return((A)handler.Apply(exn));
     }
 }
Ejemplo n.º 4
0
        public static void Test()
        {
            var list = new List <IItem <object> >();

            list.Add(new Item <object>());
            list.Add(new Item <string>());

            IItem <object> obj = new Item <string>();

            Fun1 <string> a    = () => "";
            Fun1 <object> fun1 = a;
        }
Ejemplo n.º 5
0
    public static string ReplaceFun <E>(object r, string s, Fun1 <koka_dot_std_regex._matched, string> repl, int all, int start)
    {
        Regex regex = (Regex)(r);
        int   count = (all != 0 ? int.MaxValue : 1);

        return(regex.Replace(s, delegate(Match match) {
            if (!match.Success)
            {
                return "";
            }
            else
            {
                return (string)repl.Apply(Matches(match));
            }
        }, count, start));
    }
Ejemplo n.º 6
0
    public Async <B> OnExn <B>(Fun1 <Exception, B> fun)
    {
        Async <B> result = new Async <B>();

        if (done)
        {
            if (exn != null)
            {
                result.Supply((B)fun.Apply(exn));
            }
        }
        if (onexn != null)
        {
            Action <Exception> prev = onexn;
            onexn = delegate(Exception x) { prev(x); result.Supply((B)fun.Apply(x)); };
        }
        else
        {
            active++;
            onexn = delegate(Exception x) { result.Supply((B)fun.Apply(x)); };
        }
        return(result);
    }
Ejemplo n.º 7
0
 public static EventloopEntry RunBlocking <A>(Action blockingAction, Fun1 <Exception, Unit> onSuccess)
 {
     return(RunBlockingPrim <Unit>(new FunFunc0 <Unit>(() => { blockingAction(); return Unit.unit; }),
                                   new FunAction2 <Exception, Unit>((exn, u) => onSuccess.Call(exn))));
 }
Ejemplo n.º 8
0
 public static B Call <A, B>(this Fun1 <A, B> f, A x)
 {
     return((B)f.Apply(x));
 }
Ejemplo n.º 9
0
 public static double F0(Fun1 F, double x) // создаю метод, который будет использовать делегат, получается в этот метож можно засунуть любой другой метод с той же сигнатурой.
 {
     return(F(x));
 }
Ejemplo n.º 10
0
 private void CalAndPush(Fun1 fun)
 {
     IConstant arg = core.PopOperand();
     core.PushOperand(fun.Invoke(arg));
 }
Ejemplo n.º 11
0
 public static Primitive.EventloopEntry SetAccessModTime(string path, double atime, double mtime, Fun1 <Exception, Unit> cb)
 {
     return(Primitive.RunBlocking <string>(() => {
         File.SetLastAccessTimeUtc(path, Primitive.FromUnixSeconds(atime));
         File.SetLastWriteTimeUtc(path, Primitive.FromUnixSeconds(mtime));
     }, cb));
 }
Ejemplo n.º 12
0
 public static Primitive.EventloopEntry WriteTextFile(string path, string content, Fun1 <Exception, Unit> cb)
 {
     return(Primitive.RunBlocking <string>(() => File.WriteAllText(path, content, Encoding.UTF8), cb));
 }