mudasobwa
Creator of Cure
LazyFor → `Kernel.SpecialForms.for/1` but returning stream
The stream-based implementation of Kernel.SpecialForms.for/1. Allows the same syntax as for and acts the same way. This is an initial release. It does not yet support :into , :uniq, and :reduce options and bitstring comprehensions.
Everything else is supported.
Examples:
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"]
Most Liked
mudasobwa
Creator of Cure
Slightly moving forward. Simple binary comprehension and options (all but :reduce) do work.
iex|1 ▶ Enum.to_list(stream <<x <- "abcabca">>, do: x)
'abcabca'
iex|2 ▶ Enum.to_list(stream <<x <- "abcabca">>, uniq: true, do: x)
'abc'
iex|3 ▶ stream <<x <- "abcabca">>, take: 2, do: x
'ab'
Also :into works as a side effect (as described here)
I am not sure I am into implementing full bitstring support, but :reduce will come soon.
4
mudasobwa
Creator of Cure
Well, the latest hot discussion about semi-mutable not actually mutable syntactic sugar reminded me of my tech debt and I implemented reduce:.
test "binary for comprehensions with reduce, generators and filters" do
bin = "abc"
acc =
stream <<x <- bin>>, Integer.is_odd(x), <<y <- "hello">>, reduce: %{} do
inner_acc -> Map.update(inner_acc, x, [y], &[y | &1])
end
assert acc == %{97 => ~c"olleh", 99 => ~c"olleh"}
end
Under the hood, the slightly modified inner clause is applied to terminate the stream. Enjoy.
2
Popular in Announcing
I’ve published the first version of my Makeup library. It’s a syntax highlighter for Elixir in the spirit of Pygments, Currently it highl...
New
Hey guyz
We at @aviabird are working on a payment library in elixir/phoenix. We are targeting March 2018 to add 56 Gateways to it.
Have...
New
Could not wait for the missing Elixir ML libraries to appear, so, I wrote one myself, taking https://github.com/sdwolfz/exlearn as a foun...
New
Hi everyone,
We would like to announce that Plataformatec is working on a new MySQL driver called MyXQL. Our goal is to eventually integ...
New
Hello guys,
I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
Hello everybody :wave:
Recently, some of my colleagues talked about database ids and uuids and their problems, and I remembered the pain...
New
Hello everyone!
I am excited to share our heart project Backpex with you.
After building several Phoenix applications, we realized that...
New
Other popular topics
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









