添加字典扩展

This commit is contained in:
Sanchime 2022-05-14 10:00:24 +08:00
parent fc916c10de
commit 1efc671213
1 changed files with 12 additions and 0 deletions

View File

@ -0,0 +1,12 @@
using Sanchime.Functional.Products;
namespace Sanchime.Functional.Extensions;
/// <summary>
/// 字典扩展
/// </summary>
public static class DictionaryExtension
{
public static Option<T> Lookup<K, T>(this Dictionary<K, T> dictionary, K key) where K: notnull
=> dictionary.TryGetValue(key, out T? value) ? Option.Some(value) : Option.None;
}