mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-06-05 14:25:17 -04:00
Progress Overhaul + Profile Page and a LOT more! (#4262)
Co-authored-by: Amelia <77553571+Fesaa@users.noreply.github.com> Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
This commit is contained in:
@@ -6,7 +6,6 @@ using API.Data.Misc;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
using API.Entities.Metadata;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace API.Extensions;
|
||||
#nullable enable
|
||||
@@ -70,6 +69,40 @@ public static class EnumerableExtensions
|
||||
return q;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Safety net around Max, returning the default value if source contains no elements
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="selector"></param>
|
||||
/// <param name="defaultValue"></param>
|
||||
/// <typeparam name="TSource"></typeparam>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static TResult? MaxOrDefault<TSource, TResult>(
|
||||
this IList<TSource> source,
|
||||
Func<TSource, TResult> selector,
|
||||
TResult? defaultValue)
|
||||
{
|
||||
return source.Count == 0 ? defaultValue : source.Max(selector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Safety wrapper around Min, returning the default value if source has no elements
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="selector"></param>
|
||||
/// <param name="defaultValue"></param>
|
||||
/// <typeparam name="TSource"></typeparam>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static TResult? MinOrDefault<TSource, TResult>(
|
||||
this IList<TSource> source,
|
||||
Func<TSource, TResult> selector,
|
||||
TResult? defaultValue)
|
||||
{
|
||||
return source.Count == 0 ? defaultValue : source.Min(selector);
|
||||
}
|
||||
|
||||
public static IEnumerable<TSource> WhereNotNull<TSource>(this IEnumerable<TSource?> source)
|
||||
where TSource : class
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user