コード例 #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));
 }