提取谓词中的冗余

问题描述

library(tidyverse)

# list all .txt files,the $ signals end of text
files <- list.files(pattern = ".txt$")

# map the files to the function read_tsv (reads in the data); 
# assign the filenames as names to the list
data <- map(files,read_tsv) %>% set_names(files)

# data is Now a list containing the data of the files;
# each slot holds data from one file

# combine the list to a single dataset/data.frame with a new variable called "file" containing the file name
data_all <- bind_rows(data,.id = "file")

我想知道c#中是否有一个选项可以提取并重新使用谓词来选择值。 这个想法是,我只有PredicateForD,并在指定在哪个嵌套对象上使用它时使用它:

var listofAs = new List<A>();   
var listofBs = new List<B>();
listofAs.AsQueryable().Where(PredicateForA(6));
listofBs.AsQueryable().Where(PredicateForB(5));

private Expression<Func<A,bool>> PredicateForA(int value)
    => x => x.B.C.D.Value == value;
private Expression<Func<B,bool>> PredicateForB(int value)
    => x => x.C.D.Value == value;
private Expression<Func<C,bool>> PredicateForC(int value)
    => x => x.D.Value == value;
private Expression<Func<D,bool>> PredicateForD(int value)
    => x => x.Value == value;

但是我无法真正弄清楚那种方式。 C#是否支持这种谓词嵌套?

编辑:谓词方法要比这复杂得多,它们可以包含70多个代码行,并且这些代码会与存在的每个嵌套对象相乘。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)