我有这个功能
result =
add 1 2 |> \a -> a % 2 == 0)
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
Elm does not use (%) as the remainder operator
Run Code Online (Sandbox Code Playgroud)
当我查看文档时,我发现我可以使用modBy
,所以我尝试了这个。
Elm does not use (%) as the remainder operator
Run Code Online (Sandbox Code Playgroud)
但这给了我以下错误。
This function cannot handle the argument sent through the (|>) pipe:
Run Code Online (Sandbox Code Playgroud)
该%
运营商辗转0.19
减少之间的混乱rem
和mod
。
modBy
并且remainderBy
是常规函数。您可以像这样使用它们:
result = add 1 2 |> (\a -> modBy 2 a == 0)
或者,如果您更喜欢代码的功能组合变体:
result = add 1 2 |> modBy 2 >> (==) 0
作为历史注释,曾经有一种方法可以使用反引号表示法调用函数中缀:
a `modBy` 2
Run Code Online (Sandbox Code Playgroud)
但这在 0.18
归档时间: |
|
查看次数: |
345 次 |
最近记录: |