Skip to content

Provide Enum.chunk_by/4 and Stream.chunk_by/4 #5888

@josevalim

Description

@josevalim

This is a generalization of the current Stream.chunk_by/2 function.

Example:

1..10
|> Stream.chunk_by([], fn i, acc ->
  if rem(i, 2) == 0, do: {Enum.reverse([i | acc]), []}, else: {[], [i | acc]}
end, fn acc -> Enum.reverse(acc) end)
|> Enum.to_list
#=> [[1, 2], [3, 4], [5, 6], [7, 8], ...]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions