Created
April 7, 2018 15:17
-
-
Save doomspork/4514f0794f5d7eea7166eb34334e29a2 to your computer and use it in GitHub Desktop.
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
defmodule Example do | |
def split(list, chunk_size) do | |
do_split(list, chunk_size, [[]]) | |
end | |
defp do_split([], _chunk_size, acc) do | |
acc | |
end | |
defp do_split([item|rest], chunk_size, [cur|acc]) do | |
if length(cur) == chunk_size do | |
do_split(rest, chunk_size, [[item] | [cur | acc]]) | |
else | |
do_split(rest, chunk_size, [[item | cur] | acc]) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment