-
Notifications
You must be signed in to change notification settings - Fork 867
Expand file tree
/
Copy pathresult.fs
More file actions
114 lines (94 loc) · 3.18 KB
/
Copy pathresult.fs
File metadata and controls
114 lines (94 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace Microsoft.FSharp.Core
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Result =
[<CompiledName("Map")>]
let inline map ([<InlineIfLambda>] mapping) result =
match result with
| Error e -> Error e
| Ok x -> Ok(mapping x)
[<CompiledName("MapError")>]
let inline mapError ([<InlineIfLambda>] mapping) result =
match result with
| Error e -> Error(mapping e)
| Ok x -> Ok x
[<CompiledName("Bind")>]
let inline bind ([<InlineIfLambda>] binder) result =
match result with
| Error e -> Error e
| Ok x -> binder x
[<CompiledName("IsOk")>]
let inline isOk result =
match result with
| Ok _ -> true
| Error _ -> false
[<CompiledName("IsError")>]
let inline isError result =
match result with
| Ok _ -> false
| Error _ -> true
[<CompiledName("DefaultValue")>]
let inline defaultValue value result =
match result with
| Error _ -> value
| Ok v -> v
[<CompiledName("DefaultWith")>]
let inline defaultWith ([<InlineIfLambda>] defThunk) result =
match result with
| Error error -> defThunk error
| Ok v -> v
[<CompiledName("Count")>]
let inline count result =
match result with
| Error _ -> 0
| Ok _ -> 1
[<CompiledName("Fold")>]
let inline fold<'T, 'Error, 'State> ([<InlineIfLambda>] folder) (state: 'State) (result: Result<'T, 'Error>) =
match result with
| Error _ -> state
| Ok x -> folder state x
[<CompiledName("FoldBack")>]
let inline foldBack<'T, 'Error, 'State> ([<InlineIfLambda>] folder) (result: Result<'T, 'Error>) (state: 'State) =
match result with
| Error _ -> state
| Ok x -> folder x state
[<CompiledName("Exists")>]
let inline exists ([<InlineIfLambda>] predicate) result =
match result with
| Error _ -> false
| Ok x -> predicate x
[<CompiledName("ForAll")>]
let inline forall ([<InlineIfLambda>] predicate) result =
match result with
| Error _ -> true
| Ok x -> predicate x
[<CompiledName("Contains")>]
let inline contains value result =
match result with
| Error _ -> false
| Ok v -> v = value
[<CompiledName("Iterate")>]
let inline iter ([<InlineIfLambda>] action) result =
match result with
| Error _ -> ()
| Ok x -> action x
[<CompiledName("ToArray")>]
let inline toArray result =
match result with
| Error _ -> [||]
| Ok x -> [| x |]
[<CompiledName("ToList")>]
let inline toList result =
match result with
| Error _ -> []
| Ok x -> [ x ]
[<CompiledName("ToOption")>]
let inline toOption result =
match result with
| Error _ -> None
| Ok x -> Some x
[<CompiledName("ToValueOption")>]
let inline toValueOption result =
match result with
| Error _ -> ValueNone
| Ok x -> ValueSome x