我的数据是SEQUENCE:
[(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)
Run Code Online (Sandbox Code Playgroud)
我创建了这些功能.
然后我想调用那些函数的"not"来将它们从序列中过滤掉.
但问题是我在前两个函数中遇到"row.Id"错误,因为你只能用一个类型来做.
我如何解决这个问题,以便我能成功地解决这个问题.
我的结果应该是SEQUENCE:
[(48,"MO);(78,"TN");(41,"VT")]
您可以使用>>operator来组合这两个函数:
let iddata =
data
|> Seq.filter (nullid >> not)
|> Seq.filter (othered >> not)
Run Code Online (Sandbox Code Playgroud)
请参见函数组合和流水线.
或者你可以使它更明确:
let iddata =
data
|> Seq.filter (fun x -> not (nullid x))
|> Seq.filter (fun x -> not (othered x))
Run Code Online (Sandbox Code Playgroud)
你可以看到它在行动:
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);;
Run Code Online (Sandbox Code Playgroud)
他们都打印 val it : seq<int> = seq [1; 2; 4; 5; ...]