小编Sim*_*ity的帖子

在 f# 中处理列表的嵌套记录

我目前在优雅地处理嵌套记录列表时遇到了一些麻烦。

假设我们有以下类型:

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)

f# readability list record

2
推荐指数
1
解决办法
343
查看次数

标签 统计

f# ×1

list ×1

readability ×1

record ×1