FP
Last updated
Was this helpful?
Last updated
Was this helpful?
Π€ΡΠ½ΠΊΡΠΈΠΎΠ½Π°ΜΠ»ΡΠ½ΠΎΠ΅ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠΈΜΡΠΎΠ²Π°Π½ΠΈΠ΅ β ΡΠ°Π·Π΄Π΅Π» ΠΈ , Π² ΠΊΠΎΡΠΎΡΠΎΠΉ ΠΏΡΠΎΡΠ΅ΡΡ ΡΡΠ°ΠΊΡΡΠ΅ΡΡΡ ΠΊΠ°ΠΊ Π²ΡΡΠΈΡΠ»Π΅Π½ΠΈΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΠΉ Π² ΠΌΠ°ΡΠ΅ΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠΎΠΌ ΠΏΠΎΠ½ΠΈΠΌΠ°Π½ΠΈΠΈ ΠΏΠΎΡΠ»Π΅Π΄Π½ΠΈΡ (Π² ΠΎΡΠ»ΠΈΡΠΈΠ΅ ΠΎΡ ΠΊΠ°ΠΊ ΠΏΠΎΠ΄ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌ Π² ).
ΠΡΠΎΡΠΈΠ²ΠΎΠΏΠΎΡΡΠ°Π²Π»ΡΠ΅ΡΡΡ ΠΏΠ°ΡΠ°Π΄ΠΈΠ³ΠΌΠ΅ , ΠΊΠΎΡΠΎΡΠ°Ρ ΠΎΠΏΠΈΡΡΠ²Π°Π΅Ρ ΠΏΡΠΎΡΠ΅ΡΡ Π²ΡΡΠΈΡΠ»Π΅Π½ΠΈΠΉ ΠΊΠ°ΠΊ ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°ΡΠ΅Π»ΡΠ½ΠΎΠ΅ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ (Π² Π·Π½Π°ΡΠ΅Π½ΠΈΠΈ, ΠΏΠΎΠ΄ΠΎΠ±Π½ΠΎΠΌ ΡΠ°ΠΊΠΎΠ²ΠΎΠΌΡ Π² ). ΠΡΠΈ Π½Π΅ΠΎΠ±Ρ ΠΎΠ΄ΠΈΠΌΠΎΡΡΠΈ, Π² ΡΡΠ½ΠΊΡΠΈΠΎΠ½Π°Π»ΡΠ½ΠΎΠΌ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠΈΡΠΎΠ²Π°Π½ΠΈΠΈ Π²ΡΡ ΡΠΎΠ²ΠΎΠΊΡΠΏΠ½ΠΎΡΡΡ ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°ΡΠ΅Π»ΡΠ½ΡΡ ΡΠΎΡΡΠΎΡΠ½ΠΈΠΉ Π²ΡΡΠΈΡΠ»ΠΈΡΠ΅Π»ΡΠ½ΠΎΠ³ΠΎ ΠΏΡΠΎΡΠ΅ΡΡΠ° ΠΏΡΠ΅Π΄ΡΡΠ°Π²Π»ΡΠ΅ΡΡΡ ΡΠ²Π½ΡΠΌ ΠΎΠ±ΡΠ°Π·ΠΎΠΌ, Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ, ΠΊΠ°ΠΊ .
Π€ΡΠ½ΠΊΡΠΈΠΎΠ½Π°Π»ΡΠ½ΠΎΠ΅ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅ ΠΏΡΠ΅Π΄ΠΏΠΎΠ»Π°Π³Π°Π΅Ρ ΠΎΠ±Ρ ΠΎΠ΄ΠΈΡΡΡΡ Π²ΡΡΠΈΡΠ»Π΅Π½ΠΈΠ΅ΠΌ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠ² ΡΡΠ½ΠΊΡΠΈΠΉ ΠΎΡ ΠΈΡΡ ΠΎΠ΄Π½ΡΡ Π΄Π°Π½Π½ΡΡ ΠΈ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠ² Π΄ΡΡΠ³ΠΈΡ ΡΡΠ½ΠΊΡΠΈΠΉ, ΠΈ Π½Π΅ ΠΏΡΠ΅Π΄ΠΏΠΎΠ»Π°Π³Π°Π΅Ρ ΡΠ²Π½ΠΎΠ³ΠΎ Ρ ΡΠ°Π½Π΅Π½ΠΈΡ ΡΠΎΡΡΠΎΡΠ½ΠΈΡ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ. Π‘ΠΎΠΎΡΠ²Π΅ΡΡΡΠ²Π΅Π½Π½ΠΎ, Π½Π΅ ΠΏΡΠ΅Π΄ΠΏΠΎΠ»Π°Π³Π°Π΅Ρ ΠΎΠ½ΠΎ ΠΈ ΠΈΠ·ΠΌΠ΅Π½ΡΠ΅ΠΌΠΎΡΡΡ ΡΡΠΎΠ³ΠΎ ΡΠΎΡΡΠΎΡΠ½ΠΈΡ (Π² ΠΎΡΠ»ΠΈΡΠΈΠ΅ ΠΎΡ , Π³Π΄Π΅ ΠΎΠ΄Π½ΠΎΠΉ ΠΈΠ· Π±Π°Π·ΠΎΠ²ΡΡ ΠΊΠΎΠ½ΡΠ΅ΠΏΡΠΈΠΉ ΡΠ²Π»ΡΠ΅ΡΡΡ , Ρ ΡΠ°Π½ΡΡΠ°Ρ ΡΠ²ΠΎΡ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ·Π²ΠΎΠ»ΡΡΡΠ°Ρ ΠΌΠ΅Π½ΡΡΡ Π΅Π³ΠΎ ΠΏΠΎ ΠΌΠ΅ΡΠ΅ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ ).
In and , a higher-order function is a that does at least one of the following:
takes one or more functions as arguments (i.e. ),
returns a function as its result.
Is a technique of fixing a number of arguments to a function, producing another function of smaller arguments i.e binding values to one or more of those arguments as the chain of function progressed.
JavaScript has the built-in method .bind
that works on functions with any number of arguments and can bind an arbitrary amount of parameters. Its invocation has the following syntax.
It turns function into a new function whose implicit this parameter is this value and whose initial arguments are always as given.
A curried function is a function that takes multiple arguments one at a time.
Curried functions on the other hand always return a unary function: a function which takes one argument.
All curried functions return partial applications, but not all partial applications are the result of curried functions.
The unary requirement for curried functions is an important feature.
ΠΠΎΠΌΠΏΠΎΠ·ΠΈΜΡΠΈΡ ΡΡΜΠ½ΠΊΡΠΈΠΉ (ΠΈΠ»ΠΈ ΡΡΠΏΠ΅ΡΠΏΠΎΠ·ΠΈΜΡΠΈΡ ΡΡΜΠ½ΠΊΡΠΈΠΉ) β ΡΡΠΎ ΠΏΡΠΈΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ ΠΎΠ΄Π½ΠΎΠΉ ΠΊ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΡ Π΄ΡΡΠ³ΠΎΠΉ.