/// <summary> /// Determines if the current optional contains a specified value. /// </summary> /// <param name="value">The value to locate.</param> /// <returns>A boolean indicating whether or not the value was found.</returns> public Task <bool> Contains(T value) { return(InnerTask.Map(option => option.Contains(value))); }
// TODO: TEST /// <summary> /// Empties an optional, if a specified condition /// is not satisfied. /// </summary> /// <param name="condition">The condition.</param> /// <returns>The filtered optional.</returns> public AsyncOption <T> Filter(bool condition) { return(InnerTask.Map(option => option.Filter(condition)).ToAsyncOption()); }
/// <summary> /// Empties an optional, if a specified predicate /// is not satisfied. /// </summary> /// <param name="predicate">The predicate.</param> /// <returns>The filtered optional.</returns> public AsyncOption <T> Filter(Func <T, bool> predicate) { return(InnerTask.Map(option => option.Filter(predicate)).ToAsyncOption()); }
/// <summary> /// Evaluates a specified action, based on whether a value is present or not. /// </summary> /// <param name="some">The action to evaluate if the value is present.</param> /// <param name="none">The action to evaluate if the value is missing.</param> public Task Match(Action <T> some, Action none) { return(InnerTask.Map(option => option.Match(some, none))); }
/// <summary> /// Transforms the inner value in an async optional /// into another optional. The result is flattened, /// and if either is empty, an empty optional is returned. /// If the option contains an exception, it is removed. /// </summary> /// <param name="mapping">The transformation function.</param> /// <returns>The transformed optional.</returns> public AsyncOption <TResult> FlatMap <TResult, TException>(Func <T, Option <TResult, TException> > mapping) { return(InnerTask.Map(option => option.FlatMap(mapping)).ToAsyncOption()); }
/// <summary> /// Evaluates a specified function, based on whether a value is present or not. /// </summary> /// <param name="some">The function to evaluate if the value is present.</param> /// <param name="none">The function to evaluate if the value is missing.</param> /// <returns>The result of the evaluated function.</returns> public Task <TResult> Match <TResult>(Func <T, TResult> some, Func <TResult> none) { return(InnerTask.Map(option => option.Match(some, none))); }
/// <summary> /// Attaches an exceptional value to an empty optional. /// </summary> /// <param name="exceptionFactory">A factory function to create an exceptional value to attach.</param> /// <returns>An optional with an exceptional value.</returns> public AsyncOption <T, TException> WithException <TException>(Func <TException> exceptionFactory) { return(InnerTask.Map(option => option.WithException(exceptionFactory)).ToAsyncOption()); }
/// <summary> /// Attaches an exceptional value to an empty optional. /// </summary> /// <param name="exception">The exceptional value to attach.</param> /// <returns>An optional with an exceptional value.</returns> public AsyncOption <T, TException> WithException <TException>(TException exception) { return(InnerTask.Map(option => option.WithException(exception)).ToAsyncOption()); }
/// <summary> /// Uses an alternative value, if no existing value is present. /// </summary> /// <param name="alternativeFactory">A factory function to create an alternative value.</param> /// <returns>A new optional, containing either the existing or alternative value.</returns> public AsyncOption <T> Or(Func <T> alternativeFactory) { return(InnerTask.Map(option => option.Or(alternativeFactory)).ToAsyncOption()); }
/// <summary> /// Uses an alternative value, if no existing value is present. /// </summary> /// <param name="alternative">The alternative value.</param> /// <returns>A new optional, containing either the existing or alternative value.</returns> public AsyncOption <T> Or(T alternative) { return(InnerTask.Map(option => option.Or(alternative)).ToAsyncOption()); }