Skip to content

Commit 32677ce

Browse files
committed
Adding uncontentious methods
1 parent 688c26b commit 32677ce

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

src/fsharp/FSharp.Core/FSharp.Core.fsproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@
7373
<Compile Include="option.fs">
7474
<Link>Collections/option.fs</Link>
7575
</Compile>
76+
<Compile Include="result.fsi">
77+
<Link>Collections/result.fsi</Link>
78+
</Compile>
79+
<Compile Include="result.fs">
80+
<Link>Collections/result.fs</Link>
81+
</Compile>
7682
<Compile Include="collections.fsi">
7783
<Link>Collections/collections.fsi</Link>
7884
</Compile>

src/fsharp/FSharp.Core/result.fs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
2+
3+
namespace Microsoft.FSharp.Core
4+
5+
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
6+
module Result =
7+
8+
[<CompiledName("Map")>]
9+
let map f inp = match inp with Error e -> Error e | Ok x -> Ok (f x)
10+
11+
[<CompiledName("MapError")>]
12+
let mapError f inp = match inp with Error e -> Error (f e) | Ok x -> Ok x
13+
14+
[<CompiledName("Bind")>]
15+
let bind f inp = match inp with Error e -> Error e | Ok x -> f x

src/fsharp/FSharp.Core/result.fsi

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
2+
3+
namespace Microsoft.FSharp.Core
4+
5+
open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
6+
7+
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
8+
module Result =
9+
10+
/// <summary><c>map f inp</c> evaluates to <c>match inp with Error e -> Error e | Ok x -> Ok (f x)</c>.</summary>
11+
/// <param name="mapping">A function to apply to the OK result value.</param>
12+
/// <param name="result">The input option.</param>
13+
/// <returns>A result of the input value after applying the mapping function, or Error if the input is Error.</returns>
14+
[<CompiledName("Map")>]
15+
val map : mapping:('T -> 'U) -> result:Result<'T, 'TError> -> Result<'U, 'TError>
16+
17+
/// <summary><c>map f inp</c> evaluates to <c>match inp with Error x -> Error (f x) | Ok v -> Ok v</c>.</summary>
18+
/// <param name="mapping">A function to apply to the OK result value.</param>
19+
/// <param name="result">The input option.</param>
20+
/// <returns>A result of the input value after applying the mapping function, or Error if the input is Error.</returns>
21+
[<CompiledName("MapError")>]
22+
val mapError: mapping:('TError -> 'U) -> result:Result<'T, 'TError> -> Result<'T, 'U>
23+
24+
/// <summary><c>bind f inp</c> evaluates to <c>match inp with Error e -> Error e | Ok x -> f x</c></summary>
25+
/// <param name="binder">A function that takes the value of type T from a result and transforms it into
26+
/// a result containing a value of type U.</param>
27+
/// <param name="result">The input result.</param>
28+
/// <returns>A result of the output type of the binder.</returns>
29+
[<CompiledName("Bind")>]
30+
val bind: binder:('T -> Result<'U, 'TError>) -> result:Result<'T, 'TError> -> Result<'U, 'TError>

0 commit comments

Comments
 (0)