Skip to content

Commit

Permalink
Add init function to array module
Browse files Browse the repository at this point in the history
  • Loading branch information
tjammer committed Nov 12, 2024
1 parent 88f71b2 commit 5d9fa73
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions std/array.smu
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ fun create(len) {
ret
}

fun init(len, value!) {
let ret& = __unsafe_array_create(len)
&__unsafe_array_length(ret) = len
fun rec inner(i) {
if i == len { () }
else {
&ret.[i] = copy(value)
inner(i + 1)
}
}
inner(0)
ret
}

fun push(arr&, value!) {
let capacity = __array_capacity(arr)
let length = length(arr)
Expand Down

0 comments on commit 5d9fa73

Please sign in to comment.