From 1b15162ba50a390c67872aa0ee56cbf461754c35 Mon Sep 17 00:00:00 2001 From: Kyle Ratti Date: Wed, 2 Aug 2023 20:26:10 -0400 Subject: [PATCH] feat: add IDictionary.TryGet to return Maybe --- Base/Structures/MaybeExtensions.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Base/Structures/MaybeExtensions.cs b/Base/Structures/MaybeExtensions.cs index bbf8452..200db43 100644 --- a/Base/Structures/MaybeExtensions.cs +++ b/Base/Structures/MaybeExtensions.cs @@ -22,6 +22,9 @@ public static class MaybeExtensions return Maybe.Empty(); } + public static Maybe TryGet(this IDictionary dict, TKey key) => + dict.TryGetValue(key, out var value) ? Maybe.Just(value) : Maybe.Empty(); + public static Maybe TryGet(this IReadOnlyDictionary dict, TKey key) => dict.TryGetValue(key, out var value) ? Maybe.Just(value) : Maybe.Empty();