【问题标题】:Skip else condition in case statement erlang在case语句erlang中跳过else条件
【发布时间】:2018-12-10 15:07:58
【问题描述】:

我有一个列表 (AllData),我正在对其进行迭代,以根据 sepc 文档条件获取一些元素。保持空元组{} 或仅ok 会导致我的列表出现问题,实际上我不想在内部case 语句的else(_->) 块中向我的NewList 插入任何内容。

我们可以跳过 else (_->) 条件吗?

这是我的示例代码:

lists:foldl(fun(X , {Counter, NewList}) ->
        case X:number() of 
          {Aa, Bb} ->
            case  X:id() == Aa of 
                true ->
                    //Aa matched 
                     {Counter+1, [X:items()|NewList] }  
                _->
                    %% I want to skip the code that goes here in inner case statement.
                    %% Doing anything here showing a wrong output. 
                    %% Keeping empty tuple with counter changing my output like 
                         {Counter+1, [[]|NewList] }  
                    %% I don't have to do anything here at all.

                end;
            _->
                 %% Execute some other code and append to J
                 {Counter+1, [X:items()|NewList] }  
         end
    end,{0, []}, AllData).

【问题讨论】:

标签: erlang


【解决方案1】:

只返回CounterNewList不变:

{Counter, NewList }

【讨论】:

  • 但我不想改变我的计数器顺序。现在我得到 [{1, []}, {2, []}, {3, []}, {5, []}, {6, []}, {10, []}]。
  • 就这么简单!我是 erlang 的新手。
  • 就是这么简单。 :-) 使用lists:foldl,如果您不想更改累加器,只需原样直接通过即可。
猜你喜欢
  • 1970-01-01
  • 2015-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多