dictionary - Map.change is not defined
问题描述
I'm trying to invoke the Map.change
function. It's clearly defined in the documentation but it just doesn't work for me. I've tried opening different namespaces (such as FSharp.Core
, Microsoft.FSharp.Collections
), with no success.
open FSharp.Collections
[<EntryPoint>]
let main argv =
let testMap = Map.empty.Add("test", true).Add("otherTest", false)
let newTestMap =
testMap
|> Map.change // Here's the error!
"otherTest"
(fun v ->
match v with
| Some b -> Some (not b)
| None -> None )
printf(newTestMap)
0
I'm getting the following error when trying to run the sample code above:
error FS0039: The value, constructor, namespace or type 'change' is not defined.
How do I use Map.change
?
解决方案
Your code works (apart from the printf
). Maybe check your F# or .NET (Core) version. The Collections namespace doesn't have to be open.
let testMap = Map.empty.Add("test", true).Add("otherTest", false)
let newTestMap =
testMap
|> Map.change // Here's the error!
"otherTest"
(fun v ->
match v with
| Some b -> Some (not b)
| None -> None )
printf "%A" newTestMap // map [("otherTest", true); ("test", true)]val it : unit = ()
推荐阅读
- reactjs - 如何在 chrome 调试器中删除断点
- r - 在 geom_line 上显示数据值
- php - 使用 Woocommerce 过滤器值作为 Redux 框架选项
- reactjs - 为什么我不能在输入中使用 maxLength?
- bash - 如何在 AWK 中整理多个文件?
- reactjs - 如何访问数组中的特定对象元素
- ffmpeg - 使用 ffmpeg 提取帧并找出它们的偏移量(毫秒)
- python-3.x - 在 Tkinter 和 Python3 中使用 entry、StringVar 和 IntVar
- python - 烧瓶:错过一些块
- javascript - 获取 XML 字段值 javascript