関数型プログラミングにおけるファンクタとは何か?
ファンクタはmap操作を提供するcontainerまたは文脈の型であり、周囲の構造を変えずに、内部の値に関数を適用できます。恒等関数をマップするとそれは変化せず、合成した関数をマップすることはマップを合成することに等しくなります。リスト、option、その他多くの型は、これらの規則のもとでファンクタです。
なぜ重要か
ファンクタという抽象により、同じmapの考え方がリスト、optional、future などにわたって一様に働きます。それを認識することで、手作業で取り出して包み直すことなく、包まれた値を変換できます。
関連ガイド
What Is a Monad?A monad is a type that wraps values and provides a way to chain operations that each return a wrapped value,…
What Is a Higher-Order Function?A higher-order function takes other functions as arguments or returns a function as its result, treating beha…
What Is an Algebraic Data Type?An algebraic data type composes types as combinations of fields and alternatives, modeling data as products a…