Skip to content

Instantly share code, notes, and snippets.

@campezzi
Created October 11, 2016 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save campezzi/6d927e25af63ec82f6ae217e050adf93 to your computer and use it in GitHub Desktop.
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
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)
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