feat: add IEnumerable<T>.Choose for Maybe
This commit is contained in:
parent
a045c76140
commit
dafaae0fab
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace FruityFoundation.Base.Structures;
|
namespace FruityFoundation.Base.Structures;
|
||||||
|
|
||||||
|
@ -23,4 +24,10 @@ public static class MaybeExtensions
|
||||||
|
|
||||||
public static T? ToNullable<T>(this Maybe<T> item) where T : struct =>
|
public static T? ToNullable<T>(this Maybe<T> item) where T : struct =>
|
||||||
item.HasValue ? item.Value : null;
|
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);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user