我的数据是一个序列:
[(40,"TX");(48,"MO");(15,"TX");(78,"TN");(41,"VT")]
我的代码如下:
type Csvfile = CsvProvider<somefile>
let data = Csvfile.GetSample().Rows
let nullid row =
row.Id = 15
let otherid row =
row.Id= 40
let iddata =
data
|> Seq.filter (not nullid)
|> Seq.filter (not otherid)
我创建函数。
然后我想调用这些函数的“not”来将它们从序列中过滤掉。
但问题是我在前两个函数中遇到了“row.Id”的错误,因为你只能用一个类型来做到这一点。
我如何解决这个问题,这样我才能成功地完成这个任务。
我的结果应该是一个序列:
[(48,"MO);(78,"TN");(41,"VT")]
您可以使用>>
运算符来组合两个函数:
let iddata =
data
|> Seq.filter (nullid >> not)
|> Seq.filter (othered >> not)
请参阅函数组合和流水线。
或者你可以让它更明确:
let iddata =
data
|> Seq.filter (fun x -> not (nullid x))
|> Seq.filter (fun x -> not (othered x))
你可以看到它在行动:
let input = [|1;2;3;4;5;6;7;8;9;10|];;
let is3 value =
value = 3;;
input |> Seq.filter (fun x -> not (is3 x));;
input |> Seq.filter (not >> is3);;
他们都打印 val it : seq<int> = seq [1; 2; 4; 5; ...]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句