Erlang中的map函数
除了具有多个元数(最多 4 个)的映射函数之外,Prolog 还允许您(在某些情况下)将多个元数函数映射到单个列表。假设您想测试“x”是否是多个列表的成员。您可以这样做:
maplist(member(x),[[a,b,c,x],[3,f,s,x]]).
包含成员的第一个参数,并将整个内容映射到列表上。
问题 1:Erlang 有类似的功能吗?我在文档中找不到它,但我在任何 Prolog 文档中也找不到它。
问题2:如何使用具有多个参数的地图(和类似功能)?自己滚?
谢谢。
In addition to having the map function available with many arities (up to 4), Prolog allows you (under certain circumstances) to map a multiple arity function onto a single list. Say you want to test whether 'x' is a member of multiple lists. You can do:
maplist(member(x),[[a,b,c,x],[3,f,s,x]]).
The first argument of member is included, and the whole thing is mapped onto the list.
Question 1: Is something similar available to Erlang? I can't find it in the documentation, but then again I can't find it in any Prolog documentation either.
Question 2: How to use map (and similar functions) with multiple arities? Roll your own?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许是这样的:
Maybe something like:
有
lists:map/2
以及列表推导式:There are
lists:map/2
and also list comprehensions: