• Stars
    star
    30
  • Rank 839,658 (Top 17 %)
  • Language
    Elixir
  • License
    MIT License
  • Created almost 8 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Queue data structure for Elixir-lang

Qex

Elixir CI Module Version Hex Docs Total Download License Last Updated

A :queue wrapper with improvements in API and addition of Protocol implementations

Protocols

Inspect, Collectable and Enumerable are implemented, use Qex with IO.inspect and Enum functions!

Function signatures

Parameters are re-ordered to better suit Elixir's awesome |>

Installation

The package can be installed as:

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

    def deps do
      [
        {:qex, "~> 0.5"}
      ]
    end
  2. Run mix deps.get

How to use

Read the docs

Protocols

iex> inspect Qex.new
"#Qex<[]>"

iex> Enum.count Qex.new(1..5)
5

iex> Enum.empty? Qex.new
true

iex> Enum.map Qex.new([1, 2, 3]), &(&1 + 1)
[2, 3, 4]

iex> inspect Enum.into(1..5, %Qex{})
"#Qex<[1, 2, 3, 4, 5]>"

# Leverages :queue.member/2 under the hood for performance
iex> Enum.member? Qex.new(1..10_000), 9_999
true

Create a new queue from a range

iex> inspect Qex.new(1..3)
"#Qex<[1, 2, 3]>"

Create a new queue from a list

iex> inspect Qex.new([1, 2, 3])
"#Qex<[1, 2, 3]>"

Add an element to the back of the queue

iex> q = Qex.new([:mid])
iex> Enum.to_list Qex.push(q, :back)
[:mid, :back]

Add an element to the front of the queue

iex> q = Qex.new([:mid])
iex> Enum.to_list Qex.push_front(q, :front)
[:front, :mid]

Get and remove an element from the front of the queue

iex> q = Qex.new([:front, :mid])
iex> {{:value, item}, _q} = Qex.pop(q)
iex> item
:front

iex> q = Qex.new
iex> {empty, _q} = Qex.pop(q)
iex> empty
:empty

Get and remove an element from the back of the queue

iex> q = Qex.new([:mid, :back])
iex> {{:value, item}, _q} = Qex.pop_back(q)
iex> item
:back

iex> q = Qex.new
iex> {empty, _q} = Qex.pop_back(q)
iex> empty
:empty

Reverse a queue

iex> q = Qex.new(1..3)
iex> Enum.to_list q
[1, 2, 3]
iex> Enum.to_list Qex.reverse(q)
[3, 2, 1]

Split a queue into two, the front n items are put in the first queue

iex> q = Qex.new 1..5
iex> {q1, q2} = Qex.split(q, 3)
iex> Enum.to_list q1
[1, 2, 3]
iex> Enum.to_list q2
[4, 5]

Join two queues together

iex> q1 = Qex.new 1..3
iex> q2 = Qex.new 4..5
iex> Enum.to_list Qex.join(q1, q2)
[1, 2, 3, 4, 5]

Return the first item

iex> q1 = Qex.new 1..3
iex> Qex.first(q1)
{:value, 1}
iex> q2 = Qex.new []
iex> Qex.first(q2)
:empty

iex> q1 = Qex.new 1..3
iex> Qex.first!(q1)
1

Return the last item

iex> q1 = Qex.new 1..3
iex> Qex.last(q1)
{:value, 3}
iex> q2 = Qex.new []
iex> Qex.last(q2)
:empty

iex> q1 = Qex.new 1..3
iex> Qex.last!(q1)
3

Why not "Queue"?

The name is taken... Hex link

Copyright and License

Copyright (c) 2022 Po Chen

This work is free. You can redistribute it and/or modify it under the terms of the MIT License. See the LICENSE.md file for more details.

More Repositories

1

scroll-trigger

Angular module that triggers actions on scrolling to a point
HTML
63
star
2

abnf_parsec

ABNF in, parser out
Elixir
47
star
3

dg

Elixir wrapper of :digraph with a pinch of protocols and sigils
Elixir
38
star
4

together

Group things together!
Elixir
35
star
5

extripe

Elixir Stripe API wrapper
Elixir
27
star
6

clusterable

Prepare elixir/erlang nodes to be clustered
Elixir
26
star
7

img-src-ondemand

This is an Angular module that delays image loading to when it appears on the screen
JavaScript
25
star
8

md-datetime

Angular material datetime picker
HTML
23
star
9

docker-nginx-lb

Dynamic container load balancing with nginx and consul template
Nginx
19
star
10

mine_sweeper

Mine Sweeper with Liveview
Elixir
17
star
11

dist_stages

Distributed GenStage cluster experiment
Elixir
16
star
12

ngx-html-syntax

Ngx (Angular2+) HTML Syntax for SublimeText
HTML
15
star
13

elixir-jwt

Yet Another JWT Lib for Elixir
Elixir
13
star
14

cookie_jar

CookieJar stores your cookies and applies them to future requests
Elixir
13
star
15

elixir-side-effect

Elixir
11
star
16

elixir-cloudflare-api-client

Cloudflare API Client for Elixir community
Elixir
7
star
17

restlax

Relax, it's just REST. Elixir REST API client builder.
Elixir
4
star
18

tusk

Elixir task library with retry, success/failure callback and timeout
Elixir
2
star
19

ts-langserver

TypeScript
2
star
20

tourny

TypeScript
2
star
21

scraper

Elixir Scraper
Elixir
2
star
22

SublimeText-Theme-XDefault

A theme for the great text editor Sublime Text 2/3. It is very much like the default theme but tweaked to be less like apple style (mainly the side bar). Also, tweaked to be more consistent in terms of color, and used icons with higher resolution.
Python
2
star
23

cighate

I hate cigarettes, who wants to second me?
Ruby
1
star
24

rails-tute-zoo

Ruby
1
star
25

docker-srs

Dockerized SRS (Simple-RTMP-Server)
Dockerfile
1
star
26

estimationer

Agile story estimation in realtime over web sockets
Python
1
star
27

aoc

Elixir
1
star
28

workspace

It's like a warehouse rather.
Python
1
star
29

elixir-imap

Elixir IMAP client
Elixir
1
star
30

fsx

File System EX
Elixir
1
star
31

httpbin_proxy

Demo of migrating existing backend to Elixir
Elixir
1
star