Search code examples
erlang

case of not returning exact list. erlang


HeirListFormatted = [{code, 1}, ...],
HeirCode = proplists:get_value(code, HeirListFormatted),
HeirList = [<<"1">>, <<"2">>, ...],
HeirListCodes = [case to_integer(X) of HeirCode -> []; _-> form_data:to_integer(X) end || X <- HeirList].

Here HeirListCodes is returning a list like this: [[],2, 3,[],...]. But I want the code in one line and HeirListCodes should return me a list like [2,3, ...].


Solution

  • Is it what you are looking for?

    [Y || X <- HeirList , Y <- [binary_to_integer(X)],Y =/= HeirCode].
    

    [Edit]

    if HeirCode == undefined:

    Without any change, the filter condition will be always true, and you will get the list of binaries transformed onto a list of integer.

    If you add the filter condition HeirCode =/= undefined this filter will be always false, so the result will be an empty list.

    So the solution really depend on the result you expect.