我目前在优雅地处理嵌套记录列表时遇到了一些麻烦。
假设我们有以下类型:
type BoxEntry = {
flag : bool
}
type Box = {
entries : BoxEntry list
}
type Entry = {
boxes : Box list
}
type Model = {
recEntries : Entry list
}
Run Code Online (Sandbox Code Playgroud)
现在假设我想设置一个特定的 boxentry bool 我有 Entry、Box 和 BoxEntry 的列表索引,但是我只发现这种方法对我有用:
let handleUnsetEntry (model : Model) (idxs : string* int * int) =
let(sendId, bi, ej) = idxs
let nEntry =
model.entries
|> List.map(fun x ->
if x.sendId = sendId then
{x with boxes =
x.boxes …Run Code Online (Sandbox Code Playgroud)