Created
October 11, 2016 23:25
-
-
Save campezzi/6d927e25af63ec82f6ae217e050adf93 to your computer and use it in GitHub Desktop.
Comparison of an imperative bit of code vs. a typical Elixir functional implementation
This file contains 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
chunk_size = 50_000 | |
lists = | |
Enum.map(0..19, fn x -> | |
range_start = x * chunk_size | |
range_end = range_start + chunk_size | |
Enum.map(range_start..range_end, fn y -> %{data: %{title: "#{y} is love, #{y} is life"}} end) | |
end) | |
Enum.each(lists, fn list -> Repo.insert_all(Meme, list) end) |
This file contains 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
chunk_size = 50_000 | |
1..1_000_000 | |
|> Stream.map(fn x -> %{data: %{title: "#{x} is love, #{x} is life"}} end) | |
|> Stream.chunk(chunk_size) | |
|> &(Repo.insert_all(Meme, &1)).() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment