float リストを Vector3 または Vector2 リストに変換しようとする 2 つのコード スニペットがあります。アイデアは、リストから一度に 2/3 の要素を取得し、それらをベクトルとして結合することです。最終結果は一連のベクトルです。
let rec vec3Seq floatList =
seq {
match floatList with
| x::y::z::tail -> yield Vector3(x,y,z)
yield! vec3Seq tail
| [] -> ()
| _ -> failwith "float array not multiple of 3?"
}
let rec vec2Seq floatList =
seq {
match floatList with
| x::y::tail -> yield Vector2(x,y)
yield! vec2Seq tail
| [] -> ()
| _ -> failwith "float array not multiple of 2?"
}
コードは非常によく似ていますが、共通部分を抽出する方法がないようです。何か案は?