예제 #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);
    }
예제 #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);
 }
예제 #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));
     }
 }
예제 #4
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);
    }
예제 #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));
    }
예제 #6
0
 public static B Call <A, B>(this Fun1 <A, B> f, A x)
 {
     return((B)f.Apply(x));
 }