NullOranje

NullOranje

While working on a work project, I found I needed a more Elixir-like queue versus the Erlang :queue module. So I decided to write one. I liked what I did, so I’m sharing it with others.

Yaq (Yet another queue) is a double-ended queue that supports both the Enumerable and Collectable protocols. I wanted something I could use with the pipe operator, since with my use case I found myself having to write a lot of functions to make :queue work correctly.

This is my first library I’m sharing with the community. I not only wanted a library I could use in my day job, but something I could take an opportunity to learn how to “do things right” so with regards to Elixir.

Source code is available on Github: GitHub - NullOranje/yaq: Yet another queue module for Elixir · GitHub
Hex package: yaq | Hex
Documentation: API Reference — yaq v1.2.0

Any and all feedback is welcome.

Showing Posts 13 to 4

NullOranje

NullOranje OP

I’ve had this same though about using atoms as markers. It’s a pretty common pattern in Erlang/OTP from what I can see, but the scenario you describe seems likely, especially when using common atoms like :ok (or nil).

I liked your suggestion about following the get/fetch/fetch! paradigm in Map and elsewhere, so I added a couple functions to the API:

  • fetch/1 and fetch_r/1 will return the tuple {value, updated_queue} if there are elements on the front or back of the queue, respectively, or :error otherwise
  • fetch!/1 and fetch_r!/1 will return the tuple {value, updated_queue} if there are elements on the front or back of the queue, respectively, or raise Yaq.EmptyQueueError otherwise

I also added a default value specification for dequeue/2 and dequeue_r/2 to follow the pattern from get.

You can only enumerate and collect from front to back, but you can reverse the queue in constant time with Yak.reverse/1, so I think it is a fair compromise.

mat-hek

mat-hek

Membrane Core Team

Oh I haven’t noticed that Yaq is not a wrapper around :queue, that’s interesting. Speaking of efficiency, do you plan to do some benchmarks? Would be nice to see how it performs compared to :queue.

NobbZ

NobbZ

nil is just an atom, specialcased by the parser to be able to leave off the colon.

In my opinion having marker or value is deemed to fail anyway. What if is I want to insert exactly the value you use as marker?

Please use a tagged tuple or at least provide an API similar to Map get/fetch/fetch! to be able to differentiate when necessary.

Also when you say, it’s collectable and enumerable, in which direction? Is there a way to collect/enumerate in the opposite direction?

NullOranje

NullOranje OP

I did, but because it is mostly wrapper for :quque, it has some of the same issues. :quque (deliberately) does not track the size of the queue, so that is an O(N) operation, which was too slow for my use case.

NullOranje

NullOranje OP

That’s my fault. The repo is public now.

This was a deliberate choice. I can show the size of the

It probably shouldn’t be.

Mostly because I’m still figuring out how typespecs work.

This is probably an artifact of some thinking. The :queue module I drew inspiration from returned an :empty atom if you tried to dequeue an empty list. I guess I didn’t like the specific atom, so I think that’s why it became a nil. My own limited knowledge probably had me explicitly describe this case.

Thinking back, I’m wondering if an atom would be a better empty queue return value.

mat-hek

mat-hek

Membrane Core Team

Hmm, seems very similar to Qex. Have you tried that one?

NobbZ

NobbZ

Yes, I’m pretty sure a @typedoc would help.

thojanssens1

thojanssens1

Sorry, in this specific case it makes no sense to me too. I thought you meant as a general rule that nil | term is useless, as term includes nil; but I thought maybe sometimes it is useful to know that the library can expect nil.
Again, in this case I don’t see why this needs to be clarified indeed.

NobbZ

NobbZ

What if is I want to store nil? Is that not allowed?

thojanssens1

thojanssens1

Thank you for sharing your work. By the way, are there other libraries like yaq? If so, what are the main differences?

What happened to the GitHub repo?

Isn’t it interesting to know whether the passed atom may be expected to be nil or not?

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
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
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New

Other Trending Topics Top

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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
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
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
CodeSync
:microphone: ElixirConf 2026 - Call for Talks is open! We’re heading to Chicago :united_states: :round_pushpin: In person + virtual :d...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews