Skip to content
vic

tallakt/stream_split

Split a stream into a head and tail, without iterating the tail

tallakt/stream_split.json
{
"createdAt": "2016-10-28T12:52:33Z",
"defaultBranch": "master",
"description": "Split a stream into a head and tail, without iterating the tail",
"fullName": "tallakt/stream_split",
"homepage": null,
"language": "Elixir",
"name": "stream_split",
"pushedAt": "2022-12-18T11:40:37Z",
"stargazersCount": 37,
"topics": [],
"updatedAt": "2024-12-30T12:18:57Z",
"url": "https://github.com/tallakt/stream_split"
}

Split a stream into a head and tail, or peek at the first n items in a stream. Both without iterating the tail of the enumerable.

http://hexdocs.pm/stream_split/

iex> {head, tail} = StreamSplit.take_and_drop(Stream.cycle(1..3), 4)
iex> head
[1, 2, 3, 1]
iex> Enum.take(tail, 7)
[2, 3, 1, 2, 3, 1, 2]
iex> {head, new_enum} = StreamSplit.peek(Stream.cycle(1..3), 4)
iex> head
[1, 2, 3, 1]
iex> Enum.take(new_enum, 7)
[1, 2, 3, 1, 2, 3, 1]

The package can be installed as:

  1. Add stream_split to your list of dependencies in mix.exs:

    def deps do
    [{:stream_split, "~> 0.1.0"}]
    end