Skip to content

Commit fc751bf

Browse files
committed
Remove result.guard
1 parent 608babd commit fc751bf

File tree

3 files changed

+1
-48
lines changed

3 files changed

+1
-48
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Unreleased
44

5-
- Updated for Gleam v0.27.0.
5+
- The `bool` module gains the `guard` function.
66
- Fixed a bug where `io.print`, `io.print_error`, and `io.print_debug` would use
77
`console.log` and add `"\n"` to the output when running on Deno.
88
- Fixed a bug where `int.floor_divide` would return the wrong result in certain

src/gleam/result.gleam

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -411,36 +411,3 @@ pub fn replace_error(result: Result(a, e1), error: e2) -> Result(a, e2) {
411411
pub fn values(results: List(Result(a, e))) -> List(a) {
412412
list.filter_map(results, fn(r) { r })
413413
}
414-
415-
/// Run a callback function if the given bool is `True`, otherwise return a
416-
/// default error value.
417-
///
418-
/// This function is suitable for `use` expressions.
419-
///
420-
/// ## Examples
421-
///
422-
/// ```gleam
423-
/// > let name = "Kamaka"
424-
/// > use <- guard(name != "", or: "Missing name")
425-
/// > Ok("Hello, " <> name)
426-
/// Ok("Hello, Kamaka")
427-
/// ```
428-
///
429-
/// ```gleam
430-
/// > let name = ""
431-
/// > use <- guard(name != "", or: "Missing name")
432-
/// > Ok("Hello, " <> name)
433-
/// Error("Missing name")
434-
/// ```
435-
///
436-
///
437-
pub fn guard(
438-
requirement: Bool,
439-
or error: e,
440-
then consequence: fn() -> Result(a, e),
441-
) -> Result(a, e) {
442-
case requirement {
443-
True -> consequence()
444-
False -> Error(error)
445-
}
446-
}

test/gleam/result_test.gleam

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,3 @@ pub fn values_test() {
205205
result.values([Ok(1), Error(""), Ok(3)])
206206
|> should.equal([1, 3])
207207
}
208-
209-
pub fn guard_test() {
210-
assert Ok(1) = {
211-
let x = 1
212-
use <- result.guard(True, or: "nope")
213-
Ok(x)
214-
}
215-
216-
assert Error("nope") = {
217-
let x = 1
218-
use <- result.guard(False, or: "nope")
219-
Ok(x)
220-
}
221-
}

0 commit comments

Comments
 (0)