Erlang の queue モジュールを一通り試す - 拡張API
drop/1 関数
drop(Q1 :: queue(Item)) -> Q2 :: queue(Item)
Q1
から前方のアイテムを削除した結果であるキューQ2
を返す。
Q1
が空の場合、理由はempty
で失敗する。
> L1 = [a,b,c,d,e]. [a,b,c,d,e] > Q1 = queue:from_list(L1). {[e,d],[a,b,c]} > Q2 = queue:drop(Q1). {[e,d],[b,c]} > L2 = queue:to_list(Q2). [b,c,d,e]
> Q = queue:new(). {[],[]} > queue:drop(Q). ** exception error: empty in function queue:drop/1 called as queue:drop({[],[]}) >
drop_r/1 関数
drop_r(Q1 :: queue(Item)) -> Q2 :: queue(Item)
Q1
から後方のアイテムを削除した結果であるキューQ2
を返す。 Q1
が空の場合、理由はempty
で失敗する。
> L1 = [a,b,c,d,e]. [a,b,c,d,e] > Q1 = queue:from_list(L1). {[e,d],[a,b,c]} > Q2 = queue:drop_r(Q1). {[d],[a,b,c]} > L2 = queue:to_list(Q2). [a,b,c,d]
get/1 関数
get(Q :: queue(Item)) -> Item
キューQ
の前にあるアイテムを返す。
Q1
が空の場合、理由はempty
で失敗する。
> L = [a,b,c]. [a,b,c] > Q = queue:from_list(L). {[c],[a,b]} > queue:get(Q). a
get_r/1 関数
get_r(Q :: queue(Item)) -> Item
キューQ
の後ろにあるアイテムを返す。
Q1
が空の場合、理由はempty
で失敗する。
> L = [a,b,c]. [a,b,c] > Q = queue:from_list(L). {[c],[a,b]} > queue:get_r(Q). c
peek/1 関数
peek(Q :: queue(Item)) -> empty | {value, Item}
Q
の前方のアイテムItem
をタプル{value, Item}
で返す。Q
が空の場合はempty
を返す。
> L = [a,b,c]. [a,b,c] > Q = queue:from_list(L). {[c],[a,b]} > queue:peek(Q). {value,a}
> E = queue:new(). {[],[]} > queue:peek(E). empty
peek_r/1 関数
peek_r(Q :: queue(Item)) -> empty | {value, Item}
Q
の後方のアイテムItem
をタプル{value, Item}
で返す。Q
が空の場合はempty
を返す。
> L = [a,b,c]. [a,b,c] > Q = queue:from_list(L). {[c],[a,b]} > queue:peek_r(Q). {value,c}
> E = queue:new(). {[],[]} > queue:peek_r(E). empty