[erlang-questions] distinguish proplists vs. lists of proplists

Drew Varner drew.varner@REDACTED
Tue Sep 15 20:26:01 CEST 2015


A property in a proplist can be an atom or a tuple.

https://gist.github.com/NineFX/c78ce7bae5b7fc6b0304 <https://gist.github.com/NineFX/c78ce7bae5b7fc6b0304>

This gist works if you are sure that you will either get a list of lists or a proplist.

In Adam’s example, the first function clause and guard sequence will match against a list of lists and any proplist.

> On Sep 15, 2015, at 7:58 PM, Adam Krupicka <akrupicka@REDACTED> wrote:
> 
> 
> Not exactly sure what you're asking, but you can use pattern matching to
> distinguish a list prom a proplist -  assuming your ordinary lists do
> not contain two-element tuples:
> 
> handle(List) when is_list(List) ->
>    ...;
> handle([{_, _} | _] = Proplist) ->
>    ....
> 
> 
> A.
> 
> Excerpts from Mr rty ff's message of 2015-09-15 16:58:33 +0000:
>> 
>> Hi
>> 
>> I write a function which gets proplists or list of proplists anf key. if the input is proplists I just use proplists:get_value to find a value corresponding to key. But if the input is lists of proplists I need to iterate over all its elements. and look for key in each of them. I amnot sure how to distinguish lists vs. proplists. lists:is_list returns true for both of them.
>> 
>> Thanks
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150915/ed9aa5a0/attachment.htm>


More information about the erlang-questions mailing list