erlang - Handling the return of the queue:out_r -
i have statement want remove last item in queue using out_r.
the docs return
result = {{value, item}, q2} | {empty, q1}
q1 = q2 = queue()
how handle if want queue item removed?
how queue , disregard {value, item}?
e.g. newqueue = queue:out_r(oldqueue)
thanks
use pattern matching!
{_, newqueue} = queue:out_r(oldqueue)
given both {value, item}
, empty
returned first element of tuple, ignoring first element want.
note queue module supports 3 apis. other apis might want better. in case, can have same function, except crashes if queue empty:
drop_r(q1) -> q2 returns queue q2 result of removing rear item q1. fails reason empty if q1 empty.
picking 1 or other depends on applications , expect in queue, if can handle empty one, etc.
Comments
Post a Comment