Skip to content

Commit 94b10e0

Browse files
committed
Refactor EnumerableExtensions methods for clarity
- Reformatted parameters in `SelectWhere<T, TR>` for readability. - Updated `SelectWhereNotNull<T, TR>` constraint to `where TR : notnull`. - Removed the nullable overload of `SelectWhereNotNull<T, TR>`. - Deleted `WhereNotNull<T>` method to simplify the interface.
1 parent c41cf9f commit 94b10e0

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

Cql/Cql.Abstractions/Abstractions/Infrastructure/EnumerableExtensions.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ public static bool TryPeek<T>(
218218
/// <param name="source">The source collection.</param>
219219
/// <param name="selector">A function to test each element for a condition and project the element into a new form.</param>
220220
/// <returns>An enumerable collection that contains the transformed elements that satisfy the condition.</returns>
221-
public static IEnumerable<TR> SelectWhere<T, TR>(this IEnumerable<T> source, Func<T, (bool include, TR resultOrDefault)> selector)
221+
public static IEnumerable<TR> SelectWhere<T, TR>(
222+
this IEnumerable<T> source,
223+
Func<T, (bool include, TR resultOrDefault)> selector)
222224
{
223225
foreach (var item in source)
224226
if (selector(item) is (include: true, { } resultOrDefault))
@@ -228,20 +230,6 @@ public static IEnumerable<TR> SelectWhere<T, TR>(this IEnumerable<T> source, Fun
228230
public static IEnumerable<TR> SelectWhereNotNull<T, TR>(
229231
this IEnumerable<T> enumerable,
230232
Func<T, TR?> selectNullable)
231-
where TR : struct =>
233+
where TR : notnull =>
232234
enumerable.SelectWhere(o => selectNullable(o) is { } r ? (true, r) : default);
233-
234-
public static IEnumerable<TR> SelectWhereNotNull<T, TR>(
235-
this IEnumerable<T> enumerable,
236-
Func<T, TR?> selectNullable)
237-
where TR : class =>
238-
enumerable.SelectWhere(o => selectNullable(o) is { } r ? (true, r) : default);
239-
240-
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> enumerable)
241-
where T : class
242-
{
243-
return enumerable
244-
.Where(x => x is not null)
245-
.Select(x => x!);
246-
}
247235
}

0 commit comments

Comments
 (0)