Skip to content

Instantly share code, notes, and snippets.

@Kalimaha
Last active January 30, 2019 06:24
Show Gist options
  • Select an option

  • Save Kalimaha/b2eff21d6986a227d35c86646bf9fb7c to your computer and use it in GitHub Desktop.

Select an option

Save Kalimaha/b2eff21d6986a227d35c86646bf9fb7c to your computer and use it in GitHub Desktop.
Flow Example
defmodule Sandbox do
def hello do
[1, 3, 5, 7]
|> Flow.from_enumerable()
|> Flow.map(&get(&1))
|> Flow.map(&process(&1))
|> Flow.reduce(fn -> [] end, fn value, acc -> [value | acc] end)
|> Enum.to_list
|> IO.inspect
:world
end
def get(id) do
%{id: id}
end
def process(payload) do
Map.merge(payload, %{ value: :rand.uniform(100) })
end
end
sandbox mix test
[
  %{id: 7, value: 49},
  %{id: 5, value: 81},
  %{id: 3, value: 5},
  %{id: 1, value: 73}
]
.

Finished in 0.03 seconds
1 test, 0 failures

Randomized with seed 963740
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment