@@ -25,6 +25,96 @@ The package can be installed as:
2525
2626[Read the docs](https: // hexdocs.pm/ qex/ Qex .html )
2727
28+ ## ## Protocols
29+
30+ iex> inspect Qex .new
31+ " #Qex<[]>"
32+
33+ iex> Enum .count Qex .new (1 .. 5 )
34+ 5
35+
36+ iex> Enum .empty? Qex .new
37+ true
38+
39+ iex> Enum .map Qex .new ([1 , 2 , 3 ]), & (&1 + 1 )
40+ [2 , 3 , 4 ]
41+
42+ iex> inspect Enum .into (1 .. 5 , %Qex {})
43+ " #Qex<[1, 2, 3, 4, 5]>"
44+
45+ ## ## Create a new queue from a range
46+
47+ iex> inspect Qex .new (1 .. 3 )
48+ " #Qex<[1, 2, 3]>"
49+
50+ ## ## Create a new queue from a list
51+
52+ iex> inspect Qex .new ([1 , 2 , 3 ])
53+ " #Qex<[1, 2, 3]>"
54+
55+ ## ## Add an element to the back of the queue
56+
57+ iex> q = Qex .new ([:mid ])
58+ iex> Enum .to_list Qex .push (q, :back )
59+ [:mid , :back ]
60+
61+ ## ## Add an element to the front of the queue
62+
63+ iex> q = Qex .new ([:mid ])
64+ iex> Enum .to_list Qex .push_front (q, :front )
65+ [:front , :mid ]
66+
67+ ## ## Get and remove an element from the front of the queue
68+
69+ iex> q = Qex .new ([:front , :mid ])
70+ iex> {{:value , item}, _q} = Qex .pop (q)
71+ iex> item
72+ :front
73+
74+ iex> q = Qex .new
75+ iex> {empty, _q} = Qex .pop (q)
76+ iex> empty
77+ :empty
78+
79+ ## ## Get and remove an element from the back of the queue
80+
81+ iex> q = Qex .new ([:mid , :back ])
82+ iex> {{:value , item}, _q} = Qex .pop_back (q)
83+ iex> item
84+ :back
85+
86+ iex> q = Qex .new
87+ iex> {empty, _q} = Qex .pop_back (q)
88+ iex> empty
89+ :empty
90+
91+ ## ## Reverse a queue
92+
93+ iex> q = Qex .new (1 .. 3 )
94+ iex> Enum .to_list q
95+ [1 , 2 , 3 ]
96+ iex> Enum .to_list Qex .reverse (q)
97+ [3 , 2 , 1 ]
98+
99+ ## ## Split a queue into two, the front n items are put in the first queue
100+
101+ iex> q = Qex .new 1 .. 5
102+ iex> {q1, q2} = Qex .split (q, 3 )
103+ iex> Enum .to_list q1
104+ [1 , 2 , 3 ]
105+ iex> Enum .to_list q2
106+ [4 , 5 ]
107+
108+
109+ ## ## Join two queues together
110+
111+ iex> q1 = Qex .new 1 .. 3
112+ iex> q2 = Qex .new 4 .. 5
113+ iex> Enum .to_list Qex .join (q1, q2)
114+ [1 , 2 , 3 , 4 , 5 ]
115+
116+
117+
28118## Why not "Queue"?
29119
30120The name is taken.. . [Hex link](https: // hex.pm/ packages/ queue)
0 commit comments