Skip to content

Commit

Permalink
[External] [stdlib] Deque - don't use non-self out args (#52550)
Browse files Browse the repository at this point in the history
[External] [stdlib] Deque - don't use non-self out args

As the original author of the Deque, I would like to propose to not use
the `out` args instead of `-> ElementType as element` in `pop()` and
`popleft()` methods.

The named return variable was just a simple convenience in these
functions and not needed at all.

In general, having something in the args list of the function that you
do not pass to the function at the call site looks weird (except for
constructors). In my opinion, it makes the function signature just less
clear to read and the return type of the function unnecessarily hidden
inside the args list.

So, let's just use normal return statements here and have a clear
function signatures.

Co-authored-by: Alvydas Vitkauskas <[email protected]>
Closes #3851
MODULAR_ORIG_COMMIT_REV_ID: acae8a18cea7f91639d059e03dff88e3e3d1f5a5
  • Loading branch information
avitkauskas authored and modularbot committed Dec 11, 2024
1 parent 9930b67 commit 8123754
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions stdlib/src/collections/deque.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ struct Deque[ElementType: CollectionElement](

return (self._data + self._head)[]

fn pop(mut self, out element: ElementType) raises:
fn pop(mut self) raises -> ElementType:
"""Removes and returns the element from the right side of the deque.
Returns:
Expand All @@ -816,9 +816,9 @@ struct Deque[ElementType: CollectionElement](
):
self._realloc(self._capacity >> 1)

return
return element

fn popleft(mut self, out element: ElementType) raises:
fn popleft(mut self) raises -> ElementType:
"""Removes and returns the element from the left side of the deque.
Returns:
Expand All @@ -840,7 +840,7 @@ struct Deque[ElementType: CollectionElement](
):
self._realloc(self._capacity >> 1)

return
return element

fn reverse(mut self):
"""Reverses the elements of the deque in-place."""
Expand Down

0 comments on commit 8123754

Please sign in to comment.