Class ResilientMemberLookup
Resilient lookup against in-memory sequences that are expected to contain at most one match
but where duplicate rows have been observed in production data (see GitHub issue Tharga/Platform#64).
Returns the first match and logs a warning when more than one match is present, instead of
throwing the way Single<TSource>(IEnumerable<TSource>, Func<TSource, bool>)
would. Duplicates are surfaced via ILogger so they can be found and cleaned up out of band.
public static class ResilientMemberLookup
- Inheritance
-
ResilientMemberLookup
- Inherited Members
Methods
PickOneOrDefault<T>(IEnumerable<T>, Func<T, bool>, ILogger, string)
Returns the first element matching predicate, or default if there is no match.
When more than one element matches, logs a warning carrying context and the match count.
Use this overload outside the team/member domain (e.g. API-key hash-collision lookups).
public static T PickOneOrDefault<T>(this IEnumerable<T> source, Func<T, bool> predicate, ILogger logger, string context)
Parameters
sourceIEnumerable<T>predicateFunc<T, bool>loggerILoggercontextstring
Returns
- T
Type Parameters
T
PickOneOrDefault<T>(IEnumerable<T>, Func<T, bool>, ILogger, string, string)
Returns the first element matching predicate, or default if there is no match.
When more than one element matches, logs a warning carrying teamKey,
lookupKey, and the match count, then returns the first match.
public static T PickOneOrDefault<T>(this IEnumerable<T> source, Func<T, bool> predicate, ILogger logger, string teamKey, string lookupKey)
Parameters
Returns
- T
Type Parameters
T
ReplaceByReference<T>(IEnumerable<T>, T, T)
Returns a new array containing every element of source, with the single instance
referentially equal to target replaced by replacement.
Used by repository write paths to update a picked row without stripping its duplicate-keyed siblings
(issue Tharga/Platform#64).
public static T[] ReplaceByReference<T>(this IEnumerable<T> source, T target, T replacement)
Parameters
sourceIEnumerable<T>targetTreplacementT
Returns
- T[]
Type Parameters
T