Skip to content

Commit 12c2a40

Browse files
bradcypertvzarytovskiiT-Gro
authored
Inline results module (#16106)
* Inline results module * adjust fsi file too --------- Co-authored-by: Vlad Zarytovskii <[email protected]> Co-authored-by: Tomas Grosup <[email protected]>
1 parent 00f4a7f commit 12c2a40

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

src/FSharp.Core/result.fs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ namespace Microsoft.FSharp.Core
66
module Result =
77

88
[<CompiledName("Map")>]
9-
let map mapping result =
9+
let inline map ([<InlineIfLambda>] mapping) result =
1010
match result with
1111
| Error e -> Error e
1212
| Ok x -> Ok(mapping x)
1313

1414
[<CompiledName("MapError")>]
15-
let mapError mapping result =
15+
let inline mapError ([<InlineIfLambda>] mapping) result =
1616
match result with
1717
| Error e -> Error(mapping e)
1818
| Ok x -> Ok x
1919

2020
[<CompiledName("Bind")>]
21-
let bind binder result =
21+
let inline bind ([<InlineIfLambda>] binder) result =
2222
match result with
2323
| Error e -> Error e
2424
| Ok x -> binder x
@@ -36,43 +36,43 @@ module Result =
3636
| Error _ -> true
3737

3838
[<CompiledName("DefaultValue")>]
39-
let defaultValue value result =
39+
let inline defaultValue value result =
4040
match result with
4141
| Error _ -> value
4242
| Ok v -> v
4343

4444
[<CompiledName("DefaultWith")>]
45-
let defaultWith defThunk result =
45+
let inline defaultWith ([<InlineIfLambda>] defThunk) result =
4646
match result with
4747
| Error error -> defThunk error
4848
| Ok v -> v
4949

5050
[<CompiledName("Count")>]
51-
let count result =
51+
let inline count result =
5252
match result with
5353
| Error _ -> 0
5454
| Ok _ -> 1
5555

5656
[<CompiledName("Fold")>]
57-
let fold<'T, 'Error, 'State> folder (state: 'State) (result: Result<'T, 'Error>) =
57+
let inline fold<'T, 'Error, 'State> ([<InlineIfLambda>] folder) (state: 'State) (result: Result<'T, 'Error>) =
5858
match result with
5959
| Error _ -> state
6060
| Ok x -> folder state x
6161

6262
[<CompiledName("FoldBack")>]
63-
let foldBack<'T, 'Error, 'State> folder (result: Result<'T, 'Error>) (state: 'State) =
63+
let inline foldBack<'T, 'Error, 'State> ([<InlineIfLambda>] folder) (result: Result<'T, 'Error>) (state: 'State) =
6464
match result with
6565
| Error _ -> state
6666
| Ok x -> folder x state
6767

6868
[<CompiledName("Exists")>]
69-
let exists predicate result =
69+
let inline exists ([<InlineIfLambda>] predicate) result =
7070
match result with
7171
| Error _ -> false
7272
| Ok x -> predicate x
7373

7474
[<CompiledName("ForAll")>]
75-
let forall predicate result =
75+
let inline forall ([<InlineIfLambda>] predicate) result =
7676
match result with
7777
| Error _ -> true
7878
| Ok x -> predicate x
@@ -84,31 +84,31 @@ module Result =
8484
| Ok v -> v = value
8585

8686
[<CompiledName("Iterate")>]
87-
let iter action result =
87+
let inline iter ([<InlineIfLambda>] action) result =
8888
match result with
8989
| Error _ -> ()
9090
| Ok x -> action x
9191

9292
[<CompiledName("ToArray")>]
93-
let toArray result =
93+
let inline toArray result =
9494
match result with
9595
| Error _ -> [||]
9696
| Ok x -> [| x |]
9797

9898
[<CompiledName("ToList")>]
99-
let toList result =
99+
let inline toList result =
100100
match result with
101101
| Error _ -> []
102102
| Ok x -> [ x ]
103103

104104
[<CompiledName("ToOption")>]
105-
let toOption result =
105+
let inline toOption result =
106106
match result with
107107
| Error _ -> None
108108
| Ok x -> Some x
109109

110110
[<CompiledName("ToValueOption")>]
111-
let toValueOption result =
111+
let inline toValueOption result =
112112
match result with
113113
| Error _ -> ValueNone
114114
| Ok x -> ValueSome x

src/FSharp.Core/result.fsi

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Result =
2525
/// </code>
2626
/// </example>
2727
[<CompiledName("Map")>]
28-
val map: mapping: ('T -> 'U) -> result: Result<'T, 'TError> -> Result<'U, 'TError>
28+
val inline map: mapping: ('T -> 'U) -> result: Result<'T, 'TError> -> Result<'U, 'TError>
2929

3030
/// <summary><c>map f inp</c> evaluates to <c>match inp with Error x -> Error (f x) | Ok v -> Ok v</c>.</summary>
3131
///
@@ -42,7 +42,7 @@ module Result =
4242
/// </code>
4343
/// </example>
4444
[<CompiledName("MapError")>]
45-
val mapError: mapping: ('TError -> 'U) -> result: Result<'T, 'TError> -> Result<'T, 'U>
45+
val inline mapError: mapping: ('TError -> 'U) -> result: Result<'T, 'TError> -> Result<'T, 'U>
4646

4747
/// <summary><c>bind f inp</c> evaluates to <c>match inp with Error e -> Error e | Ok x -> f x</c></summary>
4848
///
@@ -67,7 +67,7 @@ module Result =
6767
/// </code>
6868
/// </example>
6969
[<CompiledName("Bind")>]
70-
val bind: binder: ('T -> Result<'U, 'TError>) -> result: Result<'T, 'TError> -> Result<'U, 'TError>
70+
val inline bind: binder: ('T -> Result<'U, 'TError>) -> result: Result<'T, 'TError> -> Result<'U, 'TError>
7171

7272
/// <summary>Returns true if the result is Ok.</summary>
7373
/// <param name="result">The input result.</param>
@@ -112,7 +112,7 @@ module Result =
112112
/// </code>
113113
/// </example>
114114
[<CompiledName("DefaultValue")>]
115-
val defaultValue: value: 'T -> result: Result<'T, 'Error> -> 'T
115+
val inline defaultValue: value: 'T -> result: Result<'T, 'Error> -> 'T
116116

117117
/// <summary>Gets the value of the result if the result is <c>Ok</c>, otherwise evaluates <paramref name="defThunk"/> and returns the result.</summary>
118118
///
@@ -129,7 +129,7 @@ module Result =
129129
/// </code>
130130
/// </example>
131131
[<CompiledName("DefaultWith")>]
132-
val defaultWith: defThunk: ('Error -> 'T) -> result: Result<'T, 'Error> -> 'T
132+
val inline defaultWith: defThunk: ('Error -> 'T) -> result: Result<'T, 'Error> -> 'T
133133

134134
/// <summary><c>count inp</c> evaluates to <c>match inp with Error _ -> 0 | Ok _ -> 1</c>.</summary>
135135
///
@@ -144,7 +144,7 @@ module Result =
144144
/// </code>
145145
/// </example>
146146
[<CompiledName("Count")>]
147-
val count: result: Result<'T, 'Error> -> int
147+
val inline count: result: Result<'T, 'Error> -> int
148148

149149
/// <summary><c>fold f s inp</c> evaluates to <c>match inp with Error _ -> s | Ok x -> f s x</c>.</summary>
150150
///
@@ -163,7 +163,7 @@ module Result =
163163
/// </code>
164164
/// </example>
165165
[<CompiledName("Fold")>]
166-
val fold<'T, 'Error, 'State> :
166+
val inline fold<'T, 'Error, 'State> :
167167
folder: ('State -> 'T -> 'State) -> state: 'State -> result: Result<'T, 'Error> -> 'State
168168

169169
/// <summary><c>fold f inp s</c> evaluates to <c>match inp with Error _ -> s | Ok x -> f x s</c>.</summary>
@@ -183,7 +183,7 @@ module Result =
183183
/// </code>
184184
/// </example>
185185
[<CompiledName("FoldBack")>]
186-
val foldBack<'T, 'Error, 'State> :
186+
val inline foldBack<'T, 'Error, 'State> :
187187
folder: ('T -> 'State -> 'State) -> result: Result<'T, 'Error> -> state: 'State -> 'State
188188

189189
/// <summary><c>exists p inp</c> evaluates to <c>match inp with Error _ -> false | Ok x -> p x</c>.</summary>
@@ -202,7 +202,7 @@ module Result =
202202
/// </code>
203203
/// </example>
204204
[<CompiledName("Exists")>]
205-
val exists: predicate: ('T -> bool) -> result: Result<'T, 'Error> -> bool
205+
val inline exists: predicate: ('T -> bool) -> result: Result<'T, 'Error> -> bool
206206

207207
/// <summary><c>forall p inp</c> evaluates to <c>match inp with Error _ -> true | Ok x -> p x</c>.</summary>
208208
///
@@ -220,7 +220,7 @@ module Result =
220220
/// </code>
221221
/// </example>
222222
[<CompiledName("ForAll")>]
223-
val forall: predicate: ('T -> bool) -> result: Result<'T, 'Error> -> bool
223+
val inline forall: predicate: ('T -> bool) -> result: Result<'T, 'Error> -> bool
224224

225225
/// <summary>Evaluates to true if <paramref name="result"/> is <c>Ok</c> and its value is equal to <paramref name="value"/>.</summary>
226226
///
@@ -251,7 +251,7 @@ module Result =
251251
/// </code>
252252
/// </example>
253253
[<CompiledName("Iterate")>]
254-
val iter: action: ('T -> unit) -> result: Result<'T, 'Error> -> unit
254+
val inline iter: action: ('T -> unit) -> result: Result<'T, 'Error> -> unit
255255

256256
/// <summary>Convert the result to an array of length 0 or 1.</summary>
257257
///
@@ -266,7 +266,7 @@ module Result =
266266
/// </code>
267267
/// </example>
268268
[<CompiledName("ToArray")>]
269-
val toArray: result: Result<'T, 'Error> -> 'T[]
269+
val inline toArray: result: Result<'T, 'Error> -> 'T[]
270270

271271
/// <summary>Convert the result to a list of length 0 or 1.</summary>
272272
///
@@ -281,7 +281,7 @@ module Result =
281281
/// </code>
282282
/// </example>
283283
[<CompiledName("ToList")>]
284-
val toList: result: Result<'T, 'Error> -> 'T list
284+
val inline toList: result: Result<'T, 'Error> -> 'T list
285285

286286
/// <summary>Convert the result to an Option value.</summary>
287287
///
@@ -296,7 +296,7 @@ module Result =
296296
/// </code>
297297
/// </example>
298298
[<CompiledName("ToOption")>]
299-
val toOption: result: Result<'T, 'Error> -> 'T option
299+
val inline toOption: result: Result<'T, 'Error> -> 'T option
300300

301301
/// <summary>Convert the result to an Option value.</summary>
302302
///
@@ -311,4 +311,4 @@ module Result =
311311
/// </code>
312312
/// </example>
313313
[<CompiledName("ToValueOption")>]
314-
val toValueOption: result: Result<'T, 'Error> -> 'T voption
314+
val inline toValueOption: result: Result<'T, 'Error> -> 'T voption

0 commit comments

Comments
 (0)