➜ 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
Last active
January 30, 2019 06:24
-
-
Save Kalimaha/b2eff21d6986a227d35c86646bf9fb7c to your computer and use it in GitHub Desktop.
Flow Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment