gpt4 book ai didi

elm - 在 elm-lang 的 case 表达式中,管道 `|` 运算符有什么作用?

转载 作者:行者123 更新时间:2023-12-03 16:30:10 27 4
gpt4 key购买 nike

我的 Elm 代码中有以下代码片段:

type alias Model =
{ content : String
}


update : Msg -> Model -> Model
update msg model =
case msg of
Change newContent ->
{ model | content = newContent }
{ model | content = newContent } 是什么意思做?
它是否分配(绑定(bind)) newContent 的值?至 model以及 content ?这就是 | 的原因吗?算子放在那里?

最佳答案

管道不是 case 表达式的一部分。它是记录更新语法,如下所述:https://elm-lang.org/docs/records#updating-records .

{ model | content = newContent }

赋值 newContentcontent model 中的字段记录。

关于elm - 在 elm-lang 的 case 表达式中,管道 `|` 运算符有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62100643/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com