2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

草莽Erlang ── 22. lists:mapfoldl

Last updated at Posted at 2023-01-12

口で言うより行うことがErlang習得への近道と信じています。

lists:mapfoldl

mapfoldl(fun((term, term) -> {term, term}), term, [term]) -> term
mapfoldl(fun((要素IN, 累積IN) -> {要素OUT, 累積OUT}), 累積の初期値, リスト) -> {新しいリスト, 累積の最終値}

map/2foldl/3を同時に実施するイメージです。

練習してみます。

% 各要素を2倍することと全要素の和を求めることを同時にやる
> lists:mapfoldl(fun (X, Acc) -> {X * 2, Acc + X} end, 0, [1, 2, 3, 4, 5]).
{[2,4,6,8,10],15}

listsモジュールには他にもリスト処理のための関数がたくさんあります。

Elixirにも挑戦したい

闘魂ElixirシリーズとElixir Schoolがオススメです。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?