From dafaae0fabe1fc8c02e26a8b7a0c650ff261f807 Mon Sep 17 00:00:00 2001
From: Kyle Ratti <kyleratti@users.noreply.github.com>
Date: Fri, 23 Dec 2022 12:35:10 -0500
Subject: [PATCH] feat: add IEnumerable<T>.Choose for Maybe

---
 Base/Structures/MaybeExtensions.cs | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/Base/Structures/MaybeExtensions.cs b/Base/Structures/MaybeExtensions.cs
index 0974bd4..1bd9ef9 100644
--- a/Base/Structures/MaybeExtensions.cs
+++ b/Base/Structures/MaybeExtensions.cs
@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Linq;
 
 namespace FruityFoundation.Base.Structures;
 
@@ -23,4 +24,10 @@ public static class MaybeExtensions
 
 	public static T? ToNullable<T>(this Maybe<T> item) where T : struct =>
 		item.HasValue ? item.Value : null;
+
+	public static IEnumerable<TOutput> Choose<TInput, TOutput>(this IEnumerable<TInput> enumerable, Func<TInput, Maybe<TOutput>> mapper) =>
+		enumerable
+			.Select(mapper)
+			.Where(x => x.HasValue)
+			.Select(x => x.Value);
 }
\ No newline at end of file