/// <summary> /// Shows usage of the synchronous FuncR method. /// </summary> /// <returns>The result of the operation.</returns> public static string FuncR_SyncSample() { int x = 0; // Create a synchronous, recursive func taking one parameter as input and returning a string. Func <int, string> a = FuncR <int, string> .Create((value, self) => { // Loop recursively until value is reached. string s = x + ","; if (x < value) { ++x; s += self(value); } return(s); }); // Execute the action with 4 loops, and return the result. return(a(4)); }
/// <summary> /// Shows usage of the asynchronous FuncR method. /// </summary> /// <returns>An async task containing the function result.</returns> public static async Task <string> FuncR_ASyncSample() { int x = 0; // Create a asynchronous, recursive func taking one parameter as input and returning a string. Func <int, Task <string> > a = FuncR <int, string> .Create(async (value, self) => { // Loop recursively until value is reached. string s = x + ","; if (x < value) { x = await Task.FromResult <int>(x + 1); s += await self(value); } return(s); }); // Execute the action with 4 loops, wait for it to complete, and return the result. return(await a(4)); }