public static IEnumerable <T> GetOrEmpty <T>(this IOption <IEnumerable <T> > option) => option.GetOrElse(Array.Empty <T>());
/// <summary> /// Create a sequence that contains the optional item or a default value. /// </summary> /// <typeparam name="T"> /// The item type. /// </typeparam> /// <param name="optionalItem"> /// The optional item. /// </param> /// <param name="valueIfNotDefined"> /// The <typeparamref name="T"/> to use if <paramref name="optionalItem"/> is not defined. /// </param> /// <returns> /// If <see cref="IOption{T}.IsDefined"/> is <c>true</c>, a single-element sequence containing the item; otherwise, a sequence containing <paramref name="valueIfNotDefined"/>. /// </returns> private static IEnumerable <T> ToSequenceOrElse <T>(this IOption <T> optionalItem, T valueIfNotDefined) { yield return(optionalItem.GetOrElse(valueIfNotDefined)); }
public RecipeCellViewModel(RecipeDetail detail, IOption <int> personCount, params UserAction <IRecipe>[] actions) { Detail = detail; Actions = actions; PersonCount = personCount.GetOrElse(detail.Recipe.PersonCount); }
/// <summary> /// Returns the value if the option is nonempty, otherwise empty enumerable. /// </summary> public static IEnumerable <A> Flatten <A>(this IOption <IEnumerable <A> > option) { return(option.GetOrElse(_ => Enumerable.Empty <A>())); }
public BracketExpression(IOption <NullableExpressionValue> nullable, IndexerArgument[] args) { this.Nullable = nullable.GetOrElse(new NullableExpressionValue(false)); this.Arguments = args; }