我是理性/ ocaml /函数式编程的新手.
我知道List.append和[] @ [],但这些功能将创造新的名单,但如何填充现有列表/阵列?
let coords: array point = [];原因代码:
type point = {x: int, y: int};
let coords: list point = [];
let append raw =>
Array.iter
(
fun data => {
let p = {x: data.x, y: data.y};
/* how to append p to coords */
()
}
)
raw;
Run Code Online (Sandbox Code Playgroud)
JS模拟:
const coords = [];
const append = raw => raw.forEach({x, y} => {
coords.push({
x: process(x),
y: …Run Code Online (Sandbox Code Playgroud)