Skip to content

Commit

Permalink
Add Maybe<T>.ToList()
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Vroonland committed Jul 9, 2020
1 parent 98eef75 commit 8cfbe6a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CSharpFunctionalExtensions/Maybe/MaybeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public static Result<T, E> ToResult<T, E>(this Maybe<T> maybe, E error)
return defaultValue;
}

public static List<T> ToList<T>(this Maybe<T> maybe)
{
return maybe.Unwrap(value => new List<T> {value}, new List<T>());
}

public static Maybe<T> Where<T>(this Maybe<T> maybe, Func<T, bool> predicate)
{
if (maybe.HasNoValue)
Expand Down

0 comments on commit 8cfbe6a

Please sign in to comment.