Removed unnecessary code in favor of null forgiving operator

This commit is contained in:
Peter
2021-07-11 21:58:19 -04:00
parent 016d658625
commit 2fd93904b1
2 changed files with 1 additions and 24 deletions

View File

@@ -102,7 +102,7 @@ namespace Game
if (input.FindFirstIndex(c => !TranslateColor(c).HasValue) is int invalidPosition)
View.NotifyInvalidColor(input[invalidPosition]);
else
return (Command.MakeGuess, new Code(input.SelectNonNull(TranslateColor)));
return (Command.MakeGuess, new Code(input.Select(c => TranslateColor(c)!.Value)));
break;
}

View File

@@ -84,28 +84,5 @@ namespace Game
return defaultValue;
}
/// <summary>
/// Maps the values of the source sequence to a nullable type and
/// returns the non-null values.
/// </summary>
/// <typeparam name="T">
/// The type of elements in the source sequence.
/// </typeparam>
/// <param name="source">
/// The source sequence.
/// </param>
/// <param name="selector">
/// The selector function.
/// </param>
public static IEnumerable<TResult> SelectNonNull<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult?> selector) where TResult: struct
{
foreach (var element in source)
{
var result = selector(element);
if (result.HasValue)
yield return result.Value;
}
}
}
}