【发布时间】:2017-11-26 07:23:18
【问题描述】:
在 Elixir 中,您可以执行以下操作:
iex> [1,2,3,4] -- [2,3]
[1,4]
Stream 类型有类似函数吗?
试图实现这一点,我有:
def stream_subtract(enum, []), do: Enum.to_list(enum)
def stream_subtract(enum1, enum2) do
head = Stream.take(enum2, 1)
new_enum1 = Stream.drop_while(enum1, &([&1] == head))
stream_subtract(new_enum1, Stream.drop(enum2, 1))
end
但是这失败了,因为[&1] 是一个列表,而不是一个流。
【问题讨论】:
-
如果你真的想处理实时流 - 其中一个流必须等待另一个流中的相关元素 - 那么 Elixir 的
Flow可能是前进的方向 hexdocs.pm/flow/Flow.html
标签: stream elixir difference subtraction