Is there a collection type in f# that has an "append" method, such that I can add an element to that collection as such:
(pseudo code)
let list = [1,2,3,4]
list.append( 5 )
print list
result : 1,2,3,4,5
Basically i need a collection that can grow at run time, I cant assume what size it will be. I couldn't find a way to do this with list or array in f#
UPDATE: I dont want to create a new list/array every time this will be happening many times. I want to append the already existing collection. I need to use the same name/symbol for the collection. F# doesn't allow me to redeclare or over write a collection, so this wouldnt work:
let A = [1,2,3]
let A = A.append 4 or A <- Array.appen A 4
You can use ResizeArray:
let list = ResizeArray([1;2;3;4])
list.Add( 5 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With