feat: add IDictionary.TryGet to return Maybe<T>
This commit is contained in:
parent
466f90cca5
commit
1b15162ba5
|
@ -22,6 +22,9 @@ public static class MaybeExtensions
|
||||||
return Maybe.Empty<T>();
|
return Maybe.Empty<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Maybe<TValue> TryGet<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key) =>
|
||||||
|
dict.TryGetValue(key, out var value) ? Maybe.Just(value) : Maybe.Empty<TValue>();
|
||||||
|
|
||||||
public static Maybe<TValue> TryGet<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dict, TKey key) =>
|
public static Maybe<TValue> TryGet<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dict, TKey key) =>
|
||||||
dict.TryGetValue(key, out var value) ? Maybe.Just(value) : Maybe.Empty<TValue>();
|
dict.TryGetValue(key, out var value) ? Maybe.Just(value) : Maybe.Empty<TValue>();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user