Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
inoas committed Jan 1, 2025
1 parent 3f032b6 commit 1a519d3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

<!-- ## [Unreleased] -->

## [4.0.0] - 2025-01-01

Bugfix release of 3.0.2 but containing breaking change:

- `given.ok_in` has the labels switched, before:

```gleam
pub fn ok_in(
result rslt: Result(a, e),
else_return consequence: fn(a) -> c,
return alternative: fn(e) -> c,
) -> c
```

after:

```gleam
pub fn ok_in(
result rslt: Result(a, e),
else_return alternative: fn(e) -> c,
return consequence: fn(a) -> c,
) -> c
```

## [3.0.2] - 2024-12-16

- Fix readme.
Expand Down
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "given"
version = "3.0.2"
version = "4.0.0"

# Fill out these fields if you intend to generate HTML documentation or publish
# your project to the Hex package manager.
Expand Down
4 changes: 2 additions & 2 deletions src/given.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ pub fn not_given(
///
pub fn ok_in(
result rslt: Result(a, e),
else_return consequence: fn(a) -> c,
return alternative: fn(e) -> c,
else_return alternative: fn(e) -> c,
return consequence: fn(a) -> c,
) -> c {
case rslt {
Ok(val) -> consequence(val)
Expand Down
18 changes: 18 additions & 0 deletions test/given_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ pub fn given_ok_in_test() {
|> should.equal(woof)
}

pub fn given_ok_in_unusual_usage_test() {
{
let result = Ok(great)
use error_value <- given.ok_in(result, return: fn(ok_value) { ok_value })
// …user handles Error value here…
error_value
}
|> should.equal(great)

{
let result = Error(woof)
use error_value <- given.ok_in(result, return: fn(ok_value) { ok_value })
// …user handles Error value here…
error_value
}
|> should.equal(woof)
}

pub fn given_error_in_test() {
{
let result = Error(woof)
Expand Down

0 comments on commit 1a519d3

Please sign in to comment.