Skip to content

Commit 02fd6d9

Browse files
committed
Relax result:map_error
1 parent 8c1557d commit 02fd6d9

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Unreleased
44

5+
- `result:map_error` has been relaxed to allow mapping to a different error
6+
type.
7+
8+
## v0.3.0 - 2019-06-25
9+
510
- The `map_dict` module gains a `fold` function.
611
- All modules moved under the `std` namespace.
712
- The `http` module has been split out into the `gleam_http` package.

gen/src/[email protected]

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ map(Result, Fun) ->
3232

3333
map_error(Result, Fun) ->
3434
case Result of
35-
{ok, _} ->
36-
Result;
35+
{ok, X} ->
36+
{ok, X};
3737

3838
{error, Error} ->
3939
{error, Fun(Error)}

gen/test/gleam@result_test.erl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ map_test() ->
2121
map_error_test() ->
2222
gleam@expect:equal(gleam@result:map_error({ok, 1}, fun(X) -> X + 1 end),
2323
{ok, 1}),
24-
gleam@expect:equal(gleam@result:map_error({error, 1}, fun(X) -> X + 1 end),
25-
{error, 2}).
24+
gleam@expect:equal(gleam@result:map_error({error, 1},
25+
fun(X) -> {<<"ok">>, X + 1} end),
26+
{error, {<<"ok">>, 2}}).
2627

2728
flatten_test() ->
2829
gleam@expect:equal(gleam@result:flatten({ok, {ok, 1}}), {ok, 1}),

src/gleam/result.gleam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn map(result, fun) {
2424

2525
pub fn map_error(result, fun) {
2626
case result {
27-
| Ok(_) -> result
27+
| Ok(x) -> Ok(x)
2828
| Error(error) -> Error(fun(error))
2929
}
3030
}

test/gleam/result_test.gleam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ pub fn map_error_test() {
3737
|> expect:equal(_, Ok(1))
3838

3939
Error(1)
40-
|> result:map_error(_, fn(x) { x + 1 })
41-
|> expect:equal(_, Error(2))
40+
|> result:map_error(_, fn(x) { {"ok", x + 1} })
41+
|> expect:equal(_, Error({"ok", 2}))
4242
}
4343

4444
pub fn flatten_test() {

0 commit comments

Comments
 (0)