public TaskOption <B> BiMapAsync(TaskOption <A> ma, Func <A, Task <B> > fa, Func <Unit, Task <B> > fb) { async Task <(bool IsSome, B?Value)> Do(TaskOption <A> mma, Func <A, Task <B> > ffa, Func <Unit, Task <B> > ffb) => await mma.MatchAsync( Some : async x => (true, await ffa(x)), None : async() => (true, await ffb(unit))).ConfigureAwait(false); return(new(Do(ma, fa, fb))); }
public Task(TaskType type, bool isActive, string path, TaskOption option = TaskOption.Nothing) { Type = type; Option = option; IsActive = isActive; Path = path; FilesTotal = 0; FilesScanned = 0; Progress = 0; }
public Task(int id, TaskType type, TaskOption option, bool isActive, string path, int filesTotal, int filesScanned, double progress, DateTime date) { Id = id; Type = type; Option = option; IsActive = isActive; Path = path; FilesTotal = filesTotal; FilesScanned = filesScanned; Progress = progress; Date = date; }
public async Task <B> MatchUnsafeAsync <B>(TaskOption <A> opt, Func <A, Task <B> > SomeAsync, Func <Task <B> > NoneAsync) { if (SomeAsync == null) { throw new ArgumentNullException(nameof(SomeAsync)); } if (NoneAsync == null) { throw new ArgumentNullException(nameof(NoneAsync)); } return(await opt.IsSome.ConfigureAwait(false) ? await SomeAsync(await opt.Value.ConfigureAwait(false)).ConfigureAwait(false) : await NoneAsync().ConfigureAwait(false)); }
public async Task <B> MatchAsync <B>(TaskOption <A> opt, Func <A, B> Some, Func <Task <B> > NoneAsync) { if (Some == null) { throw new ArgumentNullException(nameof(Some)); } if (NoneAsync == null) { throw new ArgumentNullException(nameof(NoneAsync)); } return(await opt.IsSome.ConfigureAwait(false) ? CheckNullReturn(Some(await opt.Value.ConfigureAwait(false))) : CheckNullReturn(await NoneAsync().ConfigureAwait(false))); }
public async Task <B> MatchUnsafe <B>(TaskOption <A> opt, Func <A, B> Some, Func <B> None) { if (Some == null) { throw new ArgumentNullException(nameof(Some)); } if (None == null) { throw new ArgumentNullException(nameof(None)); } return(await opt.IsSome.ConfigureAwait(false) ? Some(await opt.Value.ConfigureAwait(false)) : None()); }
/// <summary> /// ValueTask will be awaited and exceptions will be logged to console (TaskOption.Safe) or managed by the Blazor framework (TaskOption.None). /// </summary> public static async void AndForget(this ValueTask task, TaskOption option) { try { await task; } catch (Exception ex) { if (option != TaskOption.Safe) { throw; } Console.WriteLine(ex); } }
/// <summary> /// Listen to user input, if the key pressed is up arrow or down arrow, then change the selected option value. /// If the user pressed enter, the end the current task. /// </summary> /// <param name="selectedOption">selectedOption not null</param> /// <param name="taskEnd">true</param> /// <returns>the updated select option value or change the task status</returns> private static TaskOption ListenUserInput(TaskOption selectedOption, ref bool finishSelect) { ConsoleKey key = Console.ReadKey().Key; switch (key){ case ConsoleKey.UpArrow: selectedOption--; break; case ConsoleKey.DownArrow: selectedOption++; break; case ConsoleKey.Enter: finishSelect = true; break; default: break; } return selectedOption; }
public async Task <Unit> MatchAsync(TaskOption <A> opt, Func <A, Task> SomeAsync, Func <Task> NoneAsync) { if (SomeAsync == null) { throw new ArgumentNullException(nameof(SomeAsync)); } if (NoneAsync == null) { throw new ArgumentNullException(nameof(NoneAsync)); } if (await opt.IsSome.ConfigureAwait(false)) { await SomeAsync(await opt.Value.ConfigureAwait(false)); } else { await NoneAsync().ConfigureAwait(false); } return(Unit.Default); }
public async Task <Unit> Match(TaskOption <A> opt, Action <A> Some, Action None) { if (Some == null) { throw new ArgumentNullException(nameof(Some)); } if (None == null) { throw new ArgumentNullException(nameof(None)); } if (await opt.IsSome.ConfigureAwait(false)) { Some(await opt.Value.ConfigureAwait(false)); } else { None(); } return(Unit.Default); }
public MB BindAsync <MonadB, MB, B>(TaskOption <A> ma, Func <A, Task <MB> > f) where MonadB : struct, MonadAsync <Unit, Unit, MB, B> => default(MonadB).RunAsync(async _ => await ma.IsSome.ConfigureAwait(false) ? await f(await ma.Value.ConfigureAwait(false)).ConfigureAwait(false) : default(MonadB).Fail(ValueIsNoneException.Default));
public TaskOption <A> OptionalAsync(Task <A> taskA) => TaskOption <A> .OptionalAsync(taskA);
public TaskOption <A> Optional(A value) => TaskOption <A> .Optional(value);
/// <summary> /// Print the main menu. /// </summary> /// <param name="selectedOption">selectedOption not null</param> /// <returns>the menu length</returns> private static int PrintMenu(TaskOption selectedOption) { string[] menuItemText = { "Circumference of a circle", "Area of a circle", "Perimeter of a square", "Area of a square", "Exit the program" }; Console.Clear(); Console.WriteLine(" Select a task:"); Console.WriteLine(" {0} ", String.Empty.PadLeft(30, '-')); for (int index = 0; index < menuItemText.Length; index++) { PrintMenuItem(menuItemText[index], index == (int) selectedOption); } Console.WriteLine(" {0} ", String.Empty.PadLeft(30, '-')); return menuItemText.Length; }
public Task <bool> IsSome(TaskOption <A> opt) => opt.IsSome;
public TaskOption <A> ReturnAsync(Func <Unit, Task <A> > f) => TaskOption <A> .SomeAsync(f(unit));
public Func <Unit, Task <S> > Fold <S>(TaskOption <A> ma, S state, Func <S, A, S> f) => async _ =>
static async TaskOption <int> ReturnOption() { await Task.Yield(); return(await TaskOption.Return(Some(1))); }
static async TaskOption <int> ReturnNone() { await Task.Yield(); return(await TaskOption.None <int>()); }
public TaskOption <A> BindReturn(Unit _, TaskOption <A> mb) => mb;
public TaskOption <A> Append(TaskOption <A> x, TaskOption <A> y) => Plus(x, y);
public baseTask(IJob job, TaskOption baseOption) { _baseOption = baseOption; _job = job; _task = CreateTask(); }
public TaskOption <A> Plus(TaskOption <A> a, TaskOption <A> b) => default(MTaskOption <A>).RunAsync(async _ => await a.IsSome.ConfigureAwait(false) ? a : b);
public TaskOption <A> Some(A value) => isnull(value) ? throw new ArgumentNullException(nameof(value)) : TaskOption <A> .Some(value);
public Task <bool> IsNone(TaskOption <A> opt) => opt.IsNone;
public TaskOption <A> SomeAsync(Task <A> taskA) => isnull(taskA) ? throw new ArgumentNullException(nameof(taskA)) : TaskOption <A> .SomeAsync(taskA);
/// <summary> /// initial task /// </summary> /// <param name="job"></param> /// <param name="interval">millisecond</param> /// <param name="option"></param> public IntervalTask(IJob job, int interval, TaskOption option) : base(job, option) { _option = option; _interval = interval; }
public TaskOption <B> MapAsync(TaskOption <A> ma, Func <A, Task <B> > f) => default(MTaskOption <A>).Bind <MTaskOption <B>, TaskOption <B>, B>(ma, a => default(MTaskOption <B>).ReturnAsync(f(a)));