Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge arrays in f#

Tags:

f#

c#-to-f#

Hav not find a method or func to join arrays, and the "@" and "+" operator not works

is there any simple func or operator to do this

like in js [...array1, element1, elment2]

given

let a = [|1;2;3|]
let b = [|2;3;4|]

want

let c = [|1;2;3;4|]
let d = [|1;2;3;2;3;4|]
like image 807
Panic Avatar asked Sep 18 '25 14:09

Panic


1 Answers

Depending on what you do arrays might be the wrong data structure for your case if find yourself appending a lot.

Array comprehension syntax gives a similar experience, yield! yields the array, and single element can be used in place.

[| yield! a; 4] = [| 1; 2; 3; 4|]

[| yield! a; yield! b |] =  [|1; 2; 3; 2; 3; 4|]
like image 123
user1981 Avatar answered Sep 21 '25 11:09

user1981