我想构建一个流畅的 api 来迭代一个数组,在这个数组中我过滤值并继续处理剩余的(不是过滤的)值。像这样的伪代码:
int[] input = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
from a in Take(3) // a = {5,4,1}
from b in Skip(4) // b = null
from c in TakeWhile(x=> x != 0) // c = {7, 2}
select new Stuff(a, b, c)
我不知道从哪里开始寻找,这样的事情的基础是什么。所以我想寻求一些帮助。
系统不应该局限于 int 数字..另一个例子:
string[] input = { "how", "are", "you", "doing", "?" };
from a in OneOf("how", "what", "where") // a = "how"
from b in Match("are") // b = "are"
from c in TakeWhile(x=> x != "?") // c = { "you", "doing" }
select new Stuff(a, b, c)
红颜莎娜
相关分类