mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-28 05:33:48 -08:00
Removed unnecessary code in favor of null forgiving operator
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user