[英]@result_list = grep { test($_) } @unfiltered_list in other languages?
One of the features I love in Perl is the LISP-inspired (?) ability to filter content out of a list of things with the simple syntax 我在Perl中喜欢的功能之一是LISP启发(?)的功能,可以使用简单的语法从内容列表中过滤出内容
@result_list = grep { test($_) } @unfiltered_list;
where test function will be applied to all the items of @unfiltered_list to produce the @result_list. 测试功能将应用于@unfiltered_list的所有项目以产生@result_list。
Is that a feature that exists in other languages as well ? 这是其他语言中也存在的功能吗? (PHP? Python?) Otherwise, how could I easily hint non-Perlers (students) about what I mean through such code ?
(PHP?Python?)否则,如何通过此类代码轻松地向非Perler(学生)暗示我的意思?
SOLUTION: filter
in most languages, as seen on wikipedia . 解决方案:
filter
大多数语言, 如Wikipedia所示 。 Thanks for the tip, dudes. 谢谢小费,伙计们。
在python中有过滤器功能:
result_list = filter(test,unfiltered_list)
In C++0x you can do this using std::copy_if
with a back_inserter
iterator. 在C ++ 0x中,您可以将
std::copy_if
与back_inserter
迭代器一起使用。 Lambda functions make this even easier too. Lambda函数也使此操作变得更加容易。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.