https://github.com/am-kantox/lazy_for
Lazy implementation of `Kernel.SpecialForms.for/1` based on streams
https://github.com/am-kantox/lazy_for
comprehension elixir elixir-lang stream stream-processing
Last synced: 7 months ago
JSON representation
Lazy implementation of `Kernel.SpecialForms.for/1` based on streams
- Host: GitHub
- URL: https://github.com/am-kantox/lazy_for
- Owner: am-kantox
- License: mit
- Created: 2019-09-17T15:10:08.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-09-02T06:56:30.000Z (about 1 year ago)
- Last Synced: 2025-03-21T12:22:00.508Z (7 months ago)
- Topics: comprehension, elixir, elixir-lang, stream, stream-processing
- Language: Elixir
- Homepage:
- Size: 453 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LazyFor [](https://kantox.com/)   [](https://coveralls.io/github/am-kantox/lazy_for?branch=master)

_Scene in club lounge, by [Thomas Rowlandson](https://en.wikipedia.org/wiki/Thomas_Rowlandson)_
## About
The stream-based implementation of [`Kernel.SpecialForms.for/1`](https://hexdocs.pm/elixir/master/Kernel.SpecialForms.html?#for/1).
Has the same syntax as its ancestor, returns a stream.
Currently supports `Enum.t()` as an input. Examples are gracefully stolen from the ancestor’s docs.
_Examples:_
```elixir
iex> import LazyFor
iex> # A list generator:
iex> result = stream n <- [1, 2, 3, 4], do: n * 2
iex> Enum.to_list(result)
[2, 4, 6, 8]iex> # A comprehension with two generators
iex> result = stream x <- [1, 2], y <- [2, 3], do: x * y
iex> Enum.to_list(result)
[2, 3, 4, 6]iex> # A comprehension with a generator and a filter
iex> result = stream n <- [1, 2, 3, 4, 5, 6], rem(n, 2) == 0, do: n
iex> Enum.to_list(result)
[2, 4, 6]iex> users = [user: "john", admin: "meg", guest: "barbara"]
iex> result = stream {type, name} when type != :guest <- users do
...> String.upcase(name)
...> end
iex> Enum.to_list(result)
["JOHN", "MEG"]iex> Enum.to_list(stream <>, c != ?\s, do: c)
'abc'
```## Installation
```elixir
def deps do
[
{:lazy_for, "~> 1.0"}
]
end
```## Changelog
### `v1.1.0`
- `reduce:` optional argument is experimentally supported
### `v1.0.0`
- version bump
### `v0.3.0`
- optional arguments `:into`, `:uniq`, and `:take`
- remaining: `:reduce`### `v0.2.0`
- assignments inside the pipeline
- support for binary comprehensions## [Documentation](https://hexdocs.pm/lazy_for).