I am attempting to use Stream.resource with an accumulator, and I cannot find a way to retrieve the accumulator after execution has finished.--defmodule DummyExternalResource do
defstruct range: nil,
done: false,
something_important: nil
def stream(external_resource) do
Stream.resource(
fn -> external_resource end,
fn (resource=%__MODULE__{done: true}) -> {:halt, resource}
(resource) ->
resource = %__MODULE__{resource|done: true, something_important: 1234}
{Enum.to_list(resource.range), resource}
end,
fn(resource) -> resource end
)
end
end
%DummyExternalResource{range: 1..25}
|> DummyExternalResource.stream
|> Stream.each(fn(a) -> IO.puts("Do something with a side effect...") end)
|> Stream.run #=> :ok
# Goal: Use lazy stream behavior, but retrieve the :something_important key after the stream is over.From the example above, I would like to execute a function on each emitted record, which is working fine.. But how can I get the "something_important" key back out after the stream has finished?Thanks,Sean
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/ae9f8680-a15b-480c-91bb-bd259dfa5360%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.