Skip to content

Commit

Permalink
rename pop_xxx_ignore to pop_xxx_exn
Browse files Browse the repository at this point in the history
  • Loading branch information
CAIMEOX authored and bobzhang committed Mar 22, 2024
1 parent 32d79bd commit 4b1e32b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 4 additions & 3 deletions deque/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ dq.front() // Some(2)
dq.length() // 3
```

If you only want to pop an element without getting the return value, you can use `pop_front_ignore()` with `pop_back_ignore()`.
If you only want to pop an element without getting the return value, you can use `pop_front_exn()` with `pop_back_exn()`.
These two functions will panic if the queue is empty.

```moonbit
let dq = Deque::[1, 2, 3, 4, 5]
dq.pop_front_ignore()
dq.pop_front_exn()
dq.front() // Some(2)
dq.pop_back_ignore()
dq.pop_back_exn()
dq.back() // Some(3)
```

Expand Down
14 changes: 8 additions & 6 deletions deque/deque.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,13 @@ pub fn push_back[T](self : Deque[T], value : T) -> Unit {

/// Removes a fornt element from a deque.
///
/// Panics if the deque is empty.
/// # Example
/// ```
/// let dq = Deque::[1, 2, 3, 4, 5]
/// dq.pop_front_ignore()
/// dq.pop_front_exn()
/// ```
pub fn pop_front_ignore[T](self : Deque[T]) -> Unit {
pub fn pop_front_exn[T](self : Deque[T]) -> Unit {
if self.len == 0 {
abort("The deque is empty!")
}
Expand All @@ -181,12 +182,13 @@ pub fn pop_front_ignore[T](self : Deque[T]) -> Unit {

/// Removes a back element from a deque.
///
/// Panics if the deque is empty.
/// # Example
/// ```
/// let dq = Deque::[1, 2, 3, 4, 5]
/// dq.pop_back_ignore()
/// dq.pop_back_exn()
/// ```
pub fn pop_back_ignore[T](self : Deque[T]) -> Unit {
pub fn pop_back_exn[T](self : Deque[T]) -> Unit {
if self.len == 0 {
abort("The deque is empty!")
}
Expand Down Expand Up @@ -347,8 +349,8 @@ test "iter" {

test "iter2" {
let v = Deque::[1, 2, 3, 4, 5]
v.pop_front_ignore()
v.pop_back_ignore()
v.pop_front_exn()
v.pop_back_exn()
let mut sum = 0
v.iter(fn { x => sum += x })
@assertion.assert_eq(sum, 9)?
Expand Down

0 comments on commit 4b1e32b

Please sign in to comment.