Skip to content

Commit eee0d59

Browse files
author
Ben Baumgold
committed
new method implementations for Stack
1 parent 1c6c2ad commit eee0d59

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/stack.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,16 @@ Get the top item from the stack. Sometimes called peek.
4343
Base.first(s::Stack) = last(s.store)
4444
Base.last(s::Stack) = first(s.store)
4545

46-
function Base.push!(s::Stack, x)
47-
push!(s.store, x)
48-
return s
49-
end
46+
Base.push!(s::Stack, x) = (push!(s.store, x); s)
47+
Base.pushfirst!(s::Stack, x) = (pushfirst!(s.store, x); s)
5048

5149
Base.pop!(s::Stack) = pop!(s.store)
50+
Base.popfirst!(s::Stack) = pop!first(s.store)
5251

5352
Base.empty!(s::Stack) = (empty!(s.store); s)
5453

54+
Base.collect(s::Stack) = collect(s.store)
55+
5556
Base.iterate(st::Stack, s...) = iterate(Iterators.reverse(st.store), s...)
5657

5758
Iterators.reverse(s::Stack{T}) where {T} = DequeIterator{T}(s.store)

0 commit comments

Comments
 (0)