blob: 133d9d59c5cb37ed475e504587407f8a3eb42e67 (
plain)
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
|
// Result represents the result of something that may succeed or fail.
// `Ok` means it was successful, `Error` means it failed.
pub fn is_ok(result) {
case result {
| Error(_) -> False
| Ok(_) -> True
}
}
pub fn is_error(result) {
case result {
| Ok(_) -> False
| Error(_) -> True
}
}
pub fn map(result, fun) {
case result {
| Ok(x) -> Ok(fun(x))
| Error(e) -> Error(e)
}
}
pub fn map_error(result, fun) {
case result {
| Ok(_) -> result
| Error(error) -> Error(fun(error))
}
}
pub fn flatten(result) {
case result {
| Ok(x) -> x
| Error(error) -> Error(error)
}
}
pub fn then(result, fun) {
case result {
| Ok(x) -> fun(x)
| Error(e) -> Error(e)
}
}
pub fn unwrap(result, default) {
case result {
| Ok(v) -> v
| Error(_) -> default
}
}
|