Skip to content

Commit a1e0b66

Browse files
authored
Merge pull request #8 from dbosoft/pull/eitherextensions
ToEitherRight ToEitherLeft IfNoneAsync +semver: major due to update of Language.Ext to 4.0.3
2 parents d2df9e5 + 59910bd commit a1e0b66

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/Dbosoft.Functional/Dbosoft.Functional.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
</PropertyGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="GitVersion.MsBuild" Version="5.6.8">
19+
<PackageReference Include="GitVersion.MsBuild" Version="5.8.1">
2020
<PrivateAssets>all</PrivateAssets>
2121
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2222
</PackageReference>
23-
<PackageReference Include="LanguageExt.Core" Version="3.4.15" />
23+
<PackageReference Include="LanguageExt.Core" Version="4.0.3" />
2424
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="5.0.0" />
2525
</ItemGroup>
2626

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
using LanguageExt;
6+
using LanguageExt.Common;
7+
8+
namespace Dbosoft.Functional
9+
{
10+
public static class EitherExtensions
11+
{
12+
13+
public static Task<Either<Error, TIn>> ToEitherRight<TIn>(this TIn right)
14+
{
15+
return Prelude.RightAsync<Error, TIn>(right).ToEither();
16+
}
17+
18+
public static Task<Either<Error, TIn>> ToEitherLeft<TIn>(this Error error)
19+
{
20+
return Prelude.LeftAsync<Error, TIn>(error).ToEither();
21+
}
22+
23+
public static Task<Either<Error, TIn>> IfNoneAsync<TIn>(this Task<Either<Error, Option<TIn>>> either,
24+
Func<Task<Either<Error, TIn>>> noneFunc)
25+
{
26+
return either.ToAsync().Bind(r => r.MatchAsync(
27+
s => Prelude.Right<Error, TIn>(s),
28+
None: noneFunc).ToAsync()
29+
).ToEither();
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)