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); }
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); }
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)); } }
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; }
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)); }
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); }
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)))); }
public static B Call <A, B>(this Fun1 <A, B> f, A x) { return((B)f.Apply(x)); }
public static double F0(Fun1 F, double x) // создаю метод, который будет использовать делегат, получается в этот метож можно засунуть любой другой метод с той же сигнатурой. { return(F(x)); }
private void CalAndPush(Fun1 fun) { IConstant arg = core.PopOperand(); core.PushOperand(fun.Invoke(arg)); }
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)); }
public static Primitive.EventloopEntry WriteTextFile(string path, string content, Fun1 <Exception, Unit> cb) { return(Primitive.RunBlocking <string>(() => File.WriteAllText(path, content, Encoding.UTF8), cb)); }