Grasping `all-the-apples-at-once' › 解法样本 Sample solutions › Erlang (Group II) [#283]

L = "aaaabbbcca",
lists:reverse(lists:foldl(
    fun
        (Elt, [ {[Elt], N} | R ]) -> [ {[Elt], N + 1} | R];
        (Elt, Acc) -> [{[Elt], 1} | Acc]
    end,
    [],
    L
)).

与 Racket 解法相似。我们看到了 Erlang 非线性模式匹配 ( non-linear pattern matching ) 的特征:在第一个模式中变量 Elt 出现了两次。
It is rather similar to the Racket solution. We see the characteristic for Erlang non-linear pattern matching: the variable Elt appears twice in the first pattern.