Enum.chunk_every
You're seeing just the function
chunk_every
, go back to Enum module for more information.
Specs
chunk_every(t(), pos_integer()) :: [list()]
Shortcut to chunk_every(enumerable, count, count)
.
Link to this function
chunk_every(enumerable, count, step, leftover \\ [])
View Source (since 1.5.0)Specs
chunk_every(t(), pos_integer(), pos_integer(), t() | :discard) :: [list()]
Returns list of lists containing count
elements each, where
each new chunk starts step
elements into the enumerable
.
step
is optional and, if not passed, defaults to count
, i.e.
chunks do not overlap.
If the last chunk does not have count
elements to fill the chunk,
elements are taken from leftover
to fill in the chunk. If leftover
does not have enough elements to fill the chunk, then a partial chunk
is returned with less than count
elements.
If :discard
is given in leftover
, the last chunk is discarded
unless it has exactly count
elements.
Examples
iex> Enum.chunk_every([1, 2, 3, 4, 5, 6], 2)
[[1, 2], [3, 4], [5, 6]]
iex> Enum.chunk_every([1, 2, 3, 4, 5, 6], 3, 2, :discard)
[[1, 2, 3], [3, 4, 5]]
iex> Enum.chunk_every([1, 2, 3, 4, 5, 6], 3, 2, [7])
[[1, 2, 3], [3, 4, 5], [5, 6, 7]]
iex> Enum.chunk_every([1, 2, 3, 4], 3, 3, [])
[[1, 2, 3], [4]]
iex> Enum.chunk_every([1, 2, 3, 4], 10)
[[1, 2, 3, 4]]
iex> Enum.chunk_every([1, 2, 3, 4, 5], 2, 3, [])
[[1, 2], [4, 5]]