10
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【TIPS】Enum.reduceでEnum.map同等の処理を書くテクニック

Posted at

この記事は、Elixir Advent Calendar 2024 シリーズ7 の4日目です


【本コラムは、2分で読め、2分で試せます】

piacere です、ご覧いただいてありがとございます :bow:

役に立つかは不明ですが、Enum.reduceでEnum.map同等の処理を書くテクニックです

まず、Enum.mapのサンプルです

[1, 2, 3]
|> Enum.map(& &1 * 3)

結果:[3, 6, 9]

これをEnum.reduceで再現すると、こうなります

[1, 2, 3]
|> Enum.reduce([], & &2 ++ [&1 * 3])

結果:[3, 6, 9]

p.s.このコラムが、面白かったり、役に立ったら…

image.png にて、どうぞ応援よろしくお願いします :bow:

10
0
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
10
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?