At the Erlang shell:
> orddict:fetch(b, [{d, 2}, {a, 1}, {b,5}, {c,9}]).
** exception error: no function clause matching
orddict:fetch(b,[{d,2},{a,1},{b,5},{c,9}])
but
> orddict:fetch(b, [{a, 1}, {b,5}, {c,9}]).
5
What am I missing here?
References: orddict:fetch/2
The orddict docs describe an orddict as orddict() = [{Key :: term(), Value :: term()}]
.
The key to the solution to this problem is in the docs:
The list is ordered after the keys.
Use orddict:from_list/1 to convert from a regular list of {key, value}
pairs.
> orddict:fetch(b, orddict:from_list([{d, 2}, {a, 1}, {b,5}, {c,9}])).
5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With