【发布时间】:2016-08-04 02:22:08
【问题描述】:
Elixir 的文档说明
drop_while(enumerable, fun)
Drops items at the beginning of the enumerable while fun returns a truthy value
但我对下面的输出感到困惑。这是否意味着一旦它得到!truthy,其他一切都被视为假?
iex> Enum.drop_while([0,1,2,3,4,5], fn(x) -> rem(x,2) == 0 end)
[1,2,3,4,5]
我希望输出为[1,3,5],因为
iex> Enum.map([0,1,2,3,4,5], fn(x) -> rem(x,2) == 0 end)
[true,false,true,false,true,false]
我试图了解它是如何工作的,而不是试图获得我想要的输出(有Enum.filter 来实现结果)
【问题讨论】:
标签: elixir