sribe

sribe

  • In my work with Elixir, one of the few things that I’ve really found missing is an efficient FIFO.

  • Do others agree with the need?

  • If so, and if no one else is working on it then I’ll volunteer to wrap Erlang’s queue class into an Elixir-idiomized Queue.

Showing Posts 1 to 10

OvermindDL1

OvermindDL1

I usually just make my own zipper for that, it’s a simple 2-tuple that allows efficient ‘rear’ (and front technically) insertion as well as efficient ‘front’ (and rear technically) popping with an occasional :lists.reverse() flipping.

sribe

sribe OP

Yeah, the list.reverse hacks are great when you’re dealing with short queues. I’ve come across the one project now where I’m dealing with longer queues and I don’t want to do that.

(I’m assuming I’m understanding what you’re doing here… But since I’ve never actually implemented that, maybe I’m imagining it to be worse performing than it is.)

OvermindDL1

OvermindDL1

It is just a 2-tuple like:

iex> newFifo = fn -> {[], []} end
#Function<20.52032458/0 in :erl_eval.expr/5>
iex> pushFifo = fn({l,r},x) -> {l,[x|r]} end
#Function<12.52032458/2 in :erl_eval.expr/5>
iex> popFifo = fn {[f|l],r} -> {f, {l,r}}; {[], r} -> case :lists.reverse(r) do []->throw "BLARGH-EMPTY"; [f|l]->{f, {l,[]}} end end
#Function<6.52032458/1 in :erl_eval.expr/5>
iex> f = newFifo.()
{[], []}
iex> f1 = f |> pushFifo.(42) |> pushFifo.(16)
{[], [16, 42]}
iex> {result, f2} = f1 |> popFifo.()
{42, {[16], []}}
iex> {result, f3} = f2 |> popFifo.()
{16, {[], []}}
iex> {result_boom, f4} = f3 |> popFifo.()
** (throw) "BLARGH-EMPTY"

And the reverse function is VERY fast, it is not a usual bottleneck anyway even with large lists.

peerreynders

peerreynders

I ran into queue in the GenStage documentation - and as such I don’t see a big issue with using Erlang libraries directly when they are not exposed through Core Elixir (possibly adapted through a super thin wrapper tailored to the specific use case without covering the full capability).

I think Elixir developers should embrace the Erlang libraries - not hide them away.

michalmuskala

michalmuskala

The :queue module is the answer. It works on the same principle that @OvermindDL1 described.

sribe

sribe OP

Yes, I was asking about wrapping it…

NobbZ

NobbZ

I think that aside from the primitives which are already wrapped in :elixir-application, the most idiomatic way to wrap erlang modules and libraries is to use them directly.

sribe

sribe OP

I disagree. The native queue library cannot be used in a pipeline; its use, to me, sticks out as very non-idiomatic elixir.

Qqwy

Qqwy

TypeCheck Core Team

I agree that :queue is not nice to pipe, and also not nice to intropect.

Its implementation itself, as a purely functional queue à la Okasaki, is wonderful.

I have used EQueue in the past, which is an Elixir wrapper around :queue.

I am unsure about my opinion of needing a queue inside of the standard library. FIFO queues are not used that often in functional programming (at least in the projects I have worked on). The most important one, the actor model message mailbox, is abstracted away from us.

I do wonder how a queue NIF would look like, though :D.

rvirding

rvirding

Creator of Erlang

There is one serious issue with the :queue module and that is that there 3 interfaces to the module, which makes it a right mess. Keeping track of which is which is a problem. :grinning: If you are going to do an elixir Queue module then pick one and stick with it.

If you do your own elixir Queue there is really no reason to interface the erlang one as the implementation part is so straight forward it is probably less code to do it yourself. I needed a queue with bounded length and found it easier to write it directly myself rather than put a wrapper around queue.

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
maennchen
:warning: Security advisory: Decimal DoS vulnerability A vulnerability has been published for decimal where very large exponents can cau...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New

Other Trending Topics Top

marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews