Reputation: 251
How to breakup this collection [1, 2, 3, 4, 5, 6]
into smaller groups?
to get this [[1, 2, 3], [4, 5, 6]]
Upvotes: 1
Views: 64
Reputation: 251
Use Enum.chunk_every/2
to split it by chunks
Enum.chunk_every([1, 2, 3, 4, 5, 6], 3)
#⇒ [[1, 2, 3], [4, 5, 6]]
or Enum.split/2
to split it into a tuple containing two parts.
Enum.split([1, 2, 3, 4, 5, 6], 3)
#⇒ {[1, 2, 3], [4, 5, 6]}
Upvotes: 7