3
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?

More than 1 year has passed since last update.

【JS・TS】矢印が2つあるアロー関数で高階関数

Posted at

はじめに

以下本を読んだときに、アロー関数について学びがあったので、記事にしました。

https://www.oreilly.co.jp/books/9784873119380/

矢印が2つあるアロー関数を書いてみる

ここで言う矢印とはになります。

以下のように、最初の矢印に関数を渡して、渡した関数に最後の矢印に値を渡すことで、高階関数を作ることができます。

const increase = (num) => num + 1
const operateNums = (fun) => (num) => fun(num);
const result = operateNums(increase)(1)
console.log(result);

最後に

自分の目標として、月1で記事を投稿する事があったため、かなり簡単なものになってしまいました。

今回書いてみた関数だと、1つの矢印で(クロージャー, 値) ⇒ {クロージャー(値)} の方が簡潔であるため、矢印を2つにする意味がありません。

そのため、どうしたら矢印を2つ以上するとベストなのかを考える必要があります。

3
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
3
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?