Skip to content

Commit

Permalink
add prepend!. closes JuliaLang#1854
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Mar 18, 2013
1 parent fa89045 commit 6ac3af4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,16 @@ function append!{T}(a::Array{T,1}, items::Array{T,1})
return a
end

function prepend!{T}(a::Array{T,1}, items::Array{T,1})
if is(T,None)
error("[] cannot grow. Instead, initialize the array with \"T[]\".")
end
n = length(items)
ccall(:jl_array_grow_beg, Void, (Any, Uint), a, n)
a[1:n] = items
return a
end

function resize!(a::Vector, nl::Integer)
l = length(a)
if nl > l
Expand Down
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ export

# dequeues
append!,
prepend!,
resize!,
insert!,
shift!,
Expand Down

0 comments on commit 6ac3af4

Please sign in to comment.