Skip to content

Commit 2ba6eaa

Browse files
authored
Merge pull request #4 from insurello/async-result-binderror
2 parents 9f42c1a + 648bb5b commit 2ba6eaa

File tree

5 files changed

+34
-24
lines changed

5 files changed

+34
-24
lines changed

.github/workflows/build_and_test.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ name: Build and Test
22

33
on:
44
push:
5-
branches:
6-
- '*'
5+
branches:
6+
- "*"
77
pull_request:
8-
branches: [ master ]
8+
branches: [master]
99

1010
jobs:
1111
build:
1212
name: Build and test
1313
runs-on: ubuntu-latest
1414

1515
steps:
16-
- uses: actions/checkout@v2
17-
- name: Setup .NET Core
18-
uses: actions/setup-dotnet@v1
19-
with:
20-
dotnet-version: 3.1.101
21-
- name: Install dependencies
22-
run: dotnet restore
23-
- name: Build
24-
run: dotnet build --configuration Release --no-restore
25-
- name: Test
26-
run: dotnet test --no-restore --verbosity normal
16+
- uses: actions/checkout@v2
17+
- name: Setup .NET Core
18+
uses: actions/setup-dotnet@v1
19+
with:
20+
dotnet-version: 3.1.101
21+
- name: Install dependencies
22+
run: dotnet restore
23+
- name: Build
24+
run: dotnet build --configuration Release --no-restore /WarnAsError
25+
- name: Test
26+
run: dotnet test --no-restore --verbosity normal

.github/workflows/publish_to_NuGet.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
release:
55
types: [created, edited]
66

7-
87
jobs:
98
publish:
109
runs-on: ubuntu-latest
@@ -23,5 +22,3 @@ jobs:
2322
env:
2423
NUGET_AUTH_TOKEN: ${{secrets.NUGET_AUTH_TOKEN}}
2524
run: dotnet nuget push Release/*.nupkg --skip-duplicate --no-symbols true --source https://api.nuget.org/v3/index.json -k ${NUGET_AUTH_TOKEN}
26-
27-

src/Insurello.AsyncExtra.Tests/Insurello.AsyncExtra.Tests.fsproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11+
<PackageReference Update="FSharp.Core" Version="4.7.2" />
1112
<Compile Include="AsyncExtraTests.fs" />
1213
<Compile Include="Main.fs" />
1314
</ItemGroup>
1415

1516
<ItemGroup>
16-
<PackageReference Include="Expecto" Version="8.*" />
17+
<PackageReference Include="Expecto" Version="9.*" />
1718
<PackageReference Include="FSharp.Core" Version="4.*" />
1819
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.*" />
1920
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />

src/Insurello.AsyncExtra/AsyncExtra.fs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,24 @@ module AsyncResult =
3737
fun f asyncResultX -> Async.map (Result.mapError f) asyncResultX
3838

3939
let bind: ('x -> AsyncResult<'y, 'err>) -> AsyncResult<'x, 'err> -> AsyncResult<'y, 'err> =
40-
fun f asyncResultX ->
41-
asyncResultX
42-
|> Async.bind (function
43-
| Ok x -> f x
44-
40+
fun successMapper ->
41+
Async.bind (function
42+
| Ok x -> successMapper x
4543
| Error err -> Async.singleton (Error err))
4644

45+
let bindError: ('errT -> AsyncResult<'x, 'errU>) -> AsyncResult<'x, 'errT> -> AsyncResult<'x, 'errU> =
46+
fun errorMapper ->
47+
Async.bind (function
48+
| Ok x -> Async.singleton (Ok x)
49+
| Error err -> errorMapper err)
50+
4751
let sequence: AsyncResult<'x, 'error> list -> AsyncResult<'x list, 'error> =
4852
let folder: AsyncResult<'x list, 'error> -> AsyncResult<'x, 'error> -> AsyncResult<'x list, 'error> =
4953
fun acc nextAsyncResult ->
50-
acc |> bind (fun okValues -> nextAsyncResult |> map (fun nextOkValue -> nextOkValue :: okValues))
54+
acc
55+
|> bind (fun okValues ->
56+
nextAsyncResult
57+
|> map (fun nextOkValue -> nextOkValue :: okValues))
5158

5259
fun asyncs ->
5360
asyncs

src/Insurello.AsyncExtra/Insurello.AsyncExtra.fsproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15+
<PackageReference Update="FSharp.Core" Version="4.7.2" />
1516
<Compile Include="AsyncExtra.fs" />
1617
</ItemGroup>
18+
<PropertyGroup>
19+
<OtherFlags>$(OtherFlags) --warnon:1182 --warnaserror:FS0025</OtherFlags>
20+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
21+
</PropertyGroup>
1722

1823
</Project>

0 commit comments

Comments
 (0)