我有一个 foo: seq<int*int>
我想拆分元组,然后将结果存储到两个变量,每个变量a seq<int>
我想知道是否有更好的方法来做到这一点,例如
let item1, item2 = foo |> ?????
Run Code Online (Sandbox Code Playgroud)
我目前的解决方案
let item1 = foo |> Seq.map(fun (f1,_) -> f1)
let item2 = foo |> Seq.map(fun (_,f2) -> f2)
Run Code Online (Sandbox Code Playgroud) 我正在按照这里的解决方案使用DateTime.TryParseExact(它比DateTime.TryParse友好得多)到DateTime选项中
为了节省您的点击,这里是代码:
let (|DateTimeExact|_|) (format: string) s =
match DateTime.TryParseExact(s, format, Globalization.CultureInfo.InvariantCulture, Globalization.DateTimeStyles.None) with
| true, d -> Some d
| _ -> None
Run Code Online (Sandbox Code Playgroud)
当我尝试使用它时(在同一个模块中.我也试过在同一个函数中定义它而没有运气),
match DateTimeExact "M-d-yyyy" dateStr with
| _ -> ()
Run Code Online (Sandbox Code Playgroud)
Visual Studio使用错误强调"DateTimeExact":
'未定义值或构造函数'DateTimeExact'
我究竟做错了什么?当我将鼠标悬停在活动模式的let绑定上时,我明白了
val( | DateTimeExact|_|) : (string -> string -> DateTime option)
Run Code Online (Sandbox Code Playgroud) f# ×2